Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
flatpak-qt-creator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
8c23bb3c
Commit
8c23bb3c
authored
Jan 06, 2009
by
hjk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some visual feedback for visual line mode
parent
2d7c5de3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
22 deletions
+78
-22
src/plugins/fakevim/handler.cpp
src/plugins/fakevim/handler.cpp
+78
-22
No files found.
src/plugins/fakevim/handler.cpp
View file @
8c23bb3c
...
...
@@ -99,6 +99,14 @@ enum SubSubMode
TickSubSubMode
// used for '
};
enum
VisualMode
{
NoVisualMode
,
VisualCharMode
,
VisualLineMode
,
VisualBlockMode
,
};
static
const
QString
ConfigStartOfLine
=
"startofline"
;
static
const
QString
ConfigOn
=
"on"
;
...
...
@@ -128,7 +136,9 @@ public:
Private
(
FakeVimHandler
*
parent
);
bool
eventFilter
(
QObject
*
ob
,
QEvent
*
ev
);
void
handleExCommand
(
const
QString
&
cmd
);
private:
static
int
shift
(
int
key
)
{
return
key
+
32
;
}
static
int
control
(
int
key
)
{
return
key
+
256
;
}
...
...
@@ -140,6 +150,7 @@ public:
void
handleExMode
(
int
key
,
const
QString
&
text
);
void
finishMovement
(
const
QString
&
text
=
QString
());
void
updateMiniBuffer
();
void
updateSelection
();
void
search
(
const
QString
&
needle
,
bool
forward
);
void
showMessage
(
const
QString
&
msg
);
...
...
@@ -167,20 +178,22 @@ public:
void
moveToNextWord
(
bool
simple
);
void
moveToWordBoundary
(
bool
simple
,
bool
forward
);
void
handleFfTt
(
int
key
);
void
handleExCommand
(
const
QString
&
cmd
);
// helper function for handleCommand. return 1 based line index.
int
readLineCode
(
QString
&
cmd
);
QTextCursor
selectRange
(
int
beginLine
,
int
endLine
);
public:
QTextEdit
*
m_textedit
;
QPlainTextEdit
*
m_plaintextedit
;
private:
FakeVimHandler
*
q
;
Mode
m_mode
;
SubMode
m_submode
;
SubSubMode
m_subsubmode
;
int
m_subsubdata
;
QString
m_input
;
QTextEdit
*
m_textedit
;
QPlainTextEdit
*
m_plaintextedit
;
QTextCursor
m_tc
;
QHash
<
int
,
QString
>
m_registers
;
int
m_register
;
...
...
@@ -225,9 +238,9 @@ public:
int
m_commandHistoryIndex
;
// visual line mode
void
enterVisual
LineMode
(
);
void
leaveVisual
Line
Mode
();
bool
m_visualLine
Mode
;
void
enterVisual
Mode
(
VisualMode
visualMode
);
void
leaveVisualMode
();
VisualMode
m_visual
Mode
;
// marks as lines
QHash
<
int
,
int
>
m_marks
;
...
...
@@ -250,7 +263,7 @@ FakeVimHandler::Private::Private(FakeVimHandler *parent)
m_gflag
=
false
;
m_textedit
=
0
;
m_plaintextedit
=
0
;
m_visual
LineMode
=
fals
e
;
m_visual
Mode
=
NoVisualMod
e
;
m_config
[
ConfigStartOfLine
]
=
ConfigOn
;
}
...
...
@@ -328,17 +341,56 @@ void FakeVimHandler::Private::finishMovement(const QString &dotCommand)
m_gflag
=
false
;
m_register
=
'"'
;
m_tc
.
clearSelection
();
updateSelection
();
updateMiniBuffer
();
}
void
FakeVimHandler
::
Private
::
updateSelection
()
{
QList
<
QTextEdit
::
ExtraSelection
>
selections
;
if
(
m_visualMode
!=
NoVisualMode
)
{
QTextEdit
::
ExtraSelection
sel
;
sel
.
cursor
=
m_tc
;
sel
.
format
=
m_tc
.
blockCharFormat
();
sel
.
format
.
setFontWeight
(
QFont
::
Bold
);
sel
.
format
.
setFontUnderline
(
true
);
int
pos
=
m_tc
.
position
();
int
anchor
=
m_marks
[
'<'
];
//qDebug() << "POS: " << pos << " ANCHOR: " << anchor;
if
(
m_visualMode
==
VisualCharMode
)
{
sel
.
cursor
.
setPosition
(
anchor
,
KeepAnchor
);
selections
.
append
(
sel
);
}
else
if
(
m_visualMode
==
VisualLineMode
)
{
sel
.
cursor
.
setPosition
(
qMin
(
pos
,
anchor
),
MoveAnchor
);
sel
.
cursor
.
movePosition
(
StartOfLine
,
MoveAnchor
);
sel
.
cursor
.
setPosition
(
qMax
(
pos
,
anchor
),
KeepAnchor
);
sel
.
cursor
.
movePosition
(
EndOfLine
,
KeepAnchor
);
selections
.
append
(
sel
);
}
else
if
(
m_visualMode
==
VisualBlockMode
)
{
// FIXME: This shows lines right now...
sel
.
cursor
.
setPosition
(
qMin
(
pos
,
anchor
),
MoveAnchor
);
sel
.
cursor
.
movePosition
(
StartOfLine
,
MoveAnchor
);
sel
.
cursor
.
setPosition
(
qMax
(
pos
,
anchor
),
KeepAnchor
);
sel
.
cursor
.
movePosition
(
EndOfLine
,
KeepAnchor
);
selections
.
append
(
sel
);
}
}
EDITOR
(
setExtraSelections
(
selections
));
}
void
FakeVimHandler
::
Private
::
updateMiniBuffer
()
{
QString
msg
;
if
(
!
m_currentMessage
.
isEmpty
())
{
msg
=
m_currentMessage
;
m_currentMessage
.
clear
();
}
else
if
(
m_visualLineMode
)
{
}
else
if
(
m_visualMode
==
VisualCharMode
)
{
msg
=
"-- VISUAL --"
;
}
else
if
(
m_visualMode
==
VisualLineMode
)
{
msg
=
"-- VISUAL LINE --"
;
}
else
if
(
m_visualMode
==
VisualBlockMode
)
{
msg
=
"-- VISUAL BLOCK --"
;
}
else
if
(
m_mode
==
InsertMode
)
{
msg
=
"-- INSERT --"
;
}
else
{
...
...
@@ -488,18 +540,18 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text)
m_submode
=
ChangeSubMode
;
m_tc
.
movePosition
(
EndOfLine
,
KeepAnchor
);
finishMovement
();
}
else
if
(
key
==
'd'
&&
m_visualLineMode
)
{
leaveVisualLineMode
();
int
beginLine
=
lineForPosition
(
m_marks
[
'<'
]);
int
endLine
=
lineForPosition
(
m_marks
[
'>'
]);
m_tc
=
selectRange
(
beginLine
,
endLine
);
m_tc
.
removeSelectedText
();
}
else
if
(
key
==
'd'
)
{
}
else
if
(
key
==
'd'
&&
m_visualMode
==
NoVisualMode
)
{
if
(
atEol
())
m_tc
.
movePosition
(
Left
,
MoveAnchor
,
1
);
m_opcount
=
m_mvcount
;
m_mvcount
.
clear
();
m_submode
=
DeleteSubMode
;
}
else
if
(
key
==
'd'
)
{
leaveVisualMode
();
int
beginLine
=
lineForPosition
(
m_marks
[
'<'
]);
int
endLine
=
lineForPosition
(
m_marks
[
'>'
]);
m_tc
=
selectRange
(
beginLine
,
endLine
);
m_tc
.
removeSelectedText
();
}
else
if
(
key
==
'D'
)
{
m_submode
=
DeleteSubMode
;
m_tc
.
movePosition
(
Down
,
KeepAnchor
,
qMax
(
count
()
-
1
,
0
));
...
...
@@ -615,8 +667,12 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text)
m_subsubdata
=
key
;
}
else
if
(
key
==
'u'
)
{
undo
();
}
else
if
(
key
==
'v'
)
{
enterVisualMode
(
VisualCharMode
);
}
else
if
(
key
==
'V'
)
{
enterVisualLineMode
();
enterVisualMode
(
VisualLineMode
);
}
else
if
(
key
==
control
(
'v'
))
{
enterVisualMode
(
VisualBlockMode
);
}
else
if
(
key
==
'w'
)
{
moveToNextWord
(
false
);
finishMovement
(
"w"
);
...
...
@@ -657,8 +713,8 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text)
}
else
if
(
key
==
Key_Delete
)
{
m_tc
.
deleteChar
();
}
else
if
(
key
==
Key_Escape
)
{
if
(
m_visual
Line
Mode
)
leaveVisual
Line
Mode
();
if
(
m_visual
Mode
!=
NoVisual
Mode
)
leaveVisualMode
();
}
else
{
qDebug
()
<<
"Ignored"
<<
key
<<
text
;
}
...
...
@@ -1135,16 +1191,16 @@ int FakeVimHandler::Private::lineForPosition(int pos) const
return
tc
.
block
().
blockNumber
()
+
1
;
}
void
FakeVimHandler
::
Private
::
enterVisual
LineMode
(
)
void
FakeVimHandler
::
Private
::
enterVisual
Mode
(
VisualMode
visualMode
)
{
m_visual
LineMode
=
tru
e
;
m_visual
Mode
=
visualMod
e
;
m_marks
[
'<'
]
=
m_tc
.
position
();
updateMiniBuffer
();
}
void
FakeVimHandler
::
Private
::
leaveVisual
Line
Mode
()
void
FakeVimHandler
::
Private
::
leaveVisualMode
()
{
m_visual
LineMode
=
fals
e
;
m_visual
Mode
=
NoVisualMod
e
;
m_marks
[
'>'
]
=
m_tc
.
position
();
updateMiniBuffer
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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