Skip to content
GitLab
Menu
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
8f8ee59d
Commit
8f8ee59d
authored
Jan 21, 2010
by
Thorbjørn Lindeijer
Browse files
Made Join Lines work with a multi-line selection
parent
bf4b5879
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/plugins/texteditor/basetexteditor.cpp
View file @
8f8ee59d
...
...
@@ -879,25 +879,36 @@ void BaseTextEditor::copyLineUpDown(bool up)
void
BaseTextEditor
::
joinLines
()
{
QTextCursor
move
=
textCursor
();
move
.
beginEditBlock
();
QTextCursor
cursor
=
textCursor
();
QTextCursor
start
=
cursor
;
QTextCursor
end
=
cursor
;
move
.
movePosition
(
QTextCursor
::
NextBlock
);
move
.
movePosition
(
QTextCursor
::
StartOfBlock
);
move
.
movePosition
(
QTextCursor
::
EndOfBlock
,
QTextCursor
::
KeepAnchor
);
QString
cutLine
=
move
.
selectedText
();
start
.
setPosition
(
cursor
.
selectionStart
());
end
.
setPosition
(
cursor
.
selectionEnd
()
-
1
);
// Collapse leading whitespaces to one or insert whitespace
cutLine
.
replace
(
QRegExp
(
"^
\\
s*"
),
" "
);
move
.
movePosition
(
QTextCursor
::
Right
,
QTextCursor
::
KeepAnchor
);
move
.
removeSelectedText
();
int
lineCount
=
qMax
(
1
,
end
.
blockNumber
()
-
start
.
blockNumber
());
cursor
.
beginEditBlock
();
cursor
.
setPosition
(
cursor
.
selectionStart
());
while
(
lineCount
--
)
{
cursor
.
movePosition
(
QTextCursor
::
NextBlock
);
cursor
.
movePosition
(
QTextCursor
::
StartOfBlock
);
cursor
.
movePosition
(
QTextCursor
::
EndOfBlock
,
QTextCursor
::
KeepAnchor
);
QString
cutLine
=
cursor
.
selectedText
();
// Collapse leading whitespaces to one or insert whitespace
cutLine
.
replace
(
QRegExp
(
"^
\\
s*"
),
" "
);
cursor
.
movePosition
(
QTextCursor
::
Right
,
QTextCursor
::
KeepAnchor
);
cursor
.
removeSelectedText
();
move
.
movePosition
(
QTextCursor
::
PreviousBlock
);
move
.
movePosition
(
QTextCursor
::
EndOfBlock
);
cursor
.
movePosition
(
QTextCursor
::
PreviousBlock
);
cursor
.
movePosition
(
QTextCursor
::
EndOfBlock
);
move
.
insertText
(
cutLine
);
move
.
endEditBlock
();
setTextCursor
(
move
);
cursor
.
insertText
(
cutLine
);
}
cursor
.
endEditBlock
();
setTextCursor
(
cursor
);
}
void
BaseTextEditor
::
moveLineUp
()
...
...
Write
Preview
Supports
Markdown
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