Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
5a32af44
Commit
5a32af44
authored
Jan 06, 2009
by
hjk
Browse files
use textedit's overwrite modus for proper cursor display.
this works with proportional fonts, too.
parent
ed6f6a2a
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/plugins/fakevim/handler.cpp
View file @
5a32af44
...
...
@@ -183,6 +183,10 @@ private:
int
readLineCode
(
QString
&
cmd
);
QTextCursor
selectRange
(
int
beginLine
,
int
endLine
);
void
enterInsertMode
();
public:
void
enterCommandMode
();
public:
QTextEdit
*
m_textedit
;
QPlainTextEdit
*
m_plaintextedit
;
...
...
@@ -601,17 +605,14 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text)
moveToFirstNonBlankOnLine
();
finishMovement
();
}
else
if
(
key
==
'i'
)
{
m_mode
=
InsertMode
;
m_lastInsertion
.
clear
();
enterInsertMode
();
updateMiniBuffer
();
}
else
if
(
key
==
'I'
)
{
m_mode
=
InsertMode
;
enter
InsertMode
()
;
if
(
m_gflag
)
m_tc
.
movePosition
(
StartOfLine
,
KeepAnchor
);
else
moveToFirstNonBlankOnLine
();
m_tc
.
clearSelection
();
m_lastInsertion
.
clear
();
}
else
if
(
key
==
'j'
||
key
==
Key_Down
)
{
m_tc
.
movePosition
(
Down
,
KeepAnchor
,
count
());
finishMovement
();
...
...
@@ -649,13 +650,11 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text)
}
else
if
(
key
==
'N'
)
{
search
(
lastSearchString
(),
!
m_lastSearchForward
);
}
else
if
(
key
==
'o'
)
{
m_mode
=
InsertMode
;
m_lastInsertion
.
clear
();
enterInsertMode
();
m_tc
.
movePosition
(
EndOfLine
,
MoveAnchor
);
m_tc
.
insertText
(
"
\n
"
);
}
else
if
(
key
==
'O'
)
{
m_mode
=
InsertMode
;
m_lastInsertion
.
clear
();
enterInsertMode
();
m_tc
.
movePosition
(
StartOfLine
,
MoveAnchor
);
m_tc
.
movePosition
(
Left
,
MoveAnchor
,
1
);
m_tc
.
insertText
(
"
\n
"
);
...
...
@@ -747,7 +746,7 @@ void FakeVimHandler::Private::handleInsertMode(int key, const QString &text)
}
recordInsert
(
m_tc
.
position
()
-
m_lastInsertion
.
size
(),
data
);
m_tc
.
movePosition
(
Left
,
MoveAnchor
,
qMin
(
1
,
leftDist
()));
m_mode
=
CommandMode
;
enter
CommandMode
()
;
}
else
if
(
key
==
Key_Left
)
{
m_tc
.
movePosition
(
Left
,
MoveAnchor
,
1
);
m_lastInsertion
.
clear
();
...
...
@@ -793,11 +792,11 @@ void FakeVimHandler::Private::handleExMode(int key, const QString &text)
if
(
key
==
Key_Escape
)
{
m_commandBuffer
.
clear
();
m_commandCode
=
0
;
m_mode
=
CommandMode
;
enter
CommandMode
()
;
updateMiniBuffer
();
}
else
if
(
key
==
Key_Backspace
)
{
if
(
m_commandBuffer
.
isEmpty
())
m_mode
=
CommandMode
;
enter
CommandMode
()
;
else
m_commandBuffer
.
chop
(
1
);
updateMiniBuffer
();
...
...
@@ -808,7 +807,7 @@ void FakeVimHandler::Private::handleExMode(int key, const QString &text)
handleExCommand
(
m_commandBuffer
);
m_commandCode
=
0
;
}
m_mode
=
CommandMode
;
enter
CommandMode
()
;
}
else
if
(
key
==
Key_Return
&&
isSearchCommand
())
{
if
(
!
m_commandBuffer
.
isEmpty
())
{
m_searchHistory
.
takeLast
();
...
...
@@ -817,7 +816,7 @@ void FakeVimHandler::Private::handleExMode(int key, const QString &text)
search
(
lastSearchString
(),
m_lastSearchForward
);
m_commandCode
=
0
;
}
m_mode
=
CommandMode
;
enter
CommandMode
()
;
updateMiniBuffer
();
}
else
if
(
key
==
Key_Up
&&
isSearchCommand
())
{
// FIXME: This and the three cases below are wrong as vim
...
...
@@ -919,7 +918,6 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
int
line
=
readLineCode
(
cmd
);
if
(
line
!=
-
1
)
m_mode
=
CommandMode
;
beginLine
=
line
;
if
(
cmd
.
startsWith
(
','
))
{
...
...
@@ -976,7 +974,7 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
m_commandBuffer
=
QString
(
"
\"
%1
\"
%2 %3L, %4C written"
)
.
arg
(
fileName
).
arg
(
exists
?
" "
:
" [New] "
)
.
arg
(
ba
.
count
(
'\n'
)).
arg
(
ba
.
size
());
m_mode
=
CommandMode
;
enter
CommandMode
()
;
updateMiniBuffer
();
}
}
else
if
(
cmd
.
startsWith
(
"r "
))
{
// :r
...
...
@@ -988,7 +986,7 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
EDITOR
(
setPlainText
(
data
));
m_commandBuffer
=
QString
(
"
\"
%1
\"
%2L, %3C"
)
.
arg
(
m_currentFileName
).
arg
(
data
.
count
(
'\n'
)).
arg
(
data
.
size
());
m_mode
=
CommandMode
;
enter
CommandMode
()
;
updateMiniBuffer
();
}
else
{
showMessage
(
"E492: Not an editor command: "
+
cmd0
);
...
...
@@ -1306,7 +1304,22 @@ void FakeVimHandler::Private::recordRemove(int position, const QString &data)
m_undoStack
.
push
(
op
);
m_redoStack
.
clear
();
}
void
FakeVimHandler
::
Private
::
enterInsertMode
()
{
EDITOR
(
setOverwriteMode
(
false
));
m_mode
=
InsertMode
;
m_lastInsertion
.
clear
();
}
void
FakeVimHandler
::
Private
::
enterCommandMode
()
{
if
(
editor
())
EDITOR
(
setOverwriteMode
(
true
));
m_mode
=
CommandMode
;
}
///////////////////////////////////////////////////////////////////////
//
// FakeVimHandler
...
...
@@ -1332,23 +1345,19 @@ bool FakeVimHandler::eventFilter(QObject *ob, QEvent *ev)
void
FakeVimHandler
::
addWidget
(
QWidget
*
widget
)
{
widget
->
installEventFilter
(
this
);
QFont
font
=
widget
->
font
();
//: -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1
//font.setFamily("Misc");
font
.
setFamily
(
"Monospace"
);
font
.
setStretch
(
QFont
::
SemiCondensed
);
widget
->
setFont
(
font
);
d
->
enterCommandMode
();
if
(
QTextEdit
*
ed
=
qobject_cast
<
QTextEdit
*>
(
widget
))
{
ed
->
setCursorWidth
(
QFontMetrics
(
ed
->
font
()).
width
(
QChar
(
'x'
)));
//
ed->setCursorWidth(QFontMetrics(ed->font()).width(QChar('x')));
ed
->
setLineWrapMode
(
QTextEdit
::
NoWrap
);
}
else
if
(
QPlainTextEdit
*
ed
=
qobject_cast
<
QPlainTextEdit
*>
(
widget
))
{
ed
->
setCursorWidth
(
QFontMetrics
(
ed
->
font
()).
width
(
QChar
(
'x'
)));
//
ed->setCursorWidth(QFontMetrics(ed->font()).width(QChar('x')));
ed
->
setLineWrapMode
(
QPlainTextEdit
::
NoWrap
);
}
}
void
FakeVimHandler
::
removeWidget
(
QWidget
*
widget
)
{
d
->
enterCommandMode
();
widget
->
removeEventFilter
(
this
);
}
...
...
tests/manual/fakevim/main.cpp
View file @
5a32af44
...
...
@@ -31,6 +31,7 @@ int main(int argc, char *argv[])
widget
->
resize
(
450
,
350
);
widget
->
setFocus
();
FakeVimHandler
fakeVim
;
QMainWindow
mw
;
...
...
@@ -40,9 +41,13 @@ int main(int argc, char *argv[])
mw
.
move
(
0
,
0
);
mw
.
show
();
QFont
font
=
mw
.
statusBar
()
->
font
();
QFont
font
=
widget
->
font
();
//: -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1
//font.setFamily("Misc");
font
.
setFamily
(
"Monospace"
);
font
.
setStretch
(
QFont
::
SemiCondensed
);
//font.setStretch(QFont::SemiCondensed);
widget
->
setFont
(
font
);
mw
.
statusBar
()
->
setFont
(
font
);
QObject
::
connect
(
&
fakeVim
,
SIGNAL
(
commandBufferChanged
(
QString
)),
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment