Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
A
awlsim
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Labels
Merge Requests
0
Merge Requests
0
Security & Compliance
Security & Compliance
Dependency List
Packages
Packages
Container Registry
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Michael Büsch
awlsim
Commits
c98927c0
Commit
c98927c0
authored
Oct 21, 2018
by
Michael Büsch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gui/editwidget: Add special case to block commenting, if last line is empty
Signed-off-by:
Michael Buesch
<
m@bues.ch
>
parent
0494e46b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
15 deletions
+24
-15
awlsim/gui/sourcecodeedit.py
awlsim/gui/sourcecodeedit.py
+24
-15
No files found.
awlsim/gui/sourcecodeedit.py
View file @
c98927c0
...
...
@@ -158,7 +158,7 @@ class SourceCodeEdit(QPlainTextEdit):
if
not
cursor
or
cursor
.
isNull
():
return
text
=
s
elf
.
toPlainText
(
)
text
=
s
tr
(
self
.
toPlainText
()
)
origStart
,
origEnd
=
cursor
.
selectionStart
(),
cursor
.
selectionEnd
()
# Extend the cursor to whole lines
...
...
@@ -169,21 +169,30 @@ class SourceCodeEdit(QPlainTextEdit):
self
.
setTextCursor
(
cursor
)
adjustedStart
,
adjustedEnd
=
cursor
.
selectionStart
(),
cursor
.
selectionEnd
()
selectedText
=
cursor
.
selectedText
()
if
not
selectedText
:
return
lines
=
selectedText
.
splitlines
()
nrCommented
=
sum
(
1
if
self
.
_lineIsCommented
(
line
)
else
0
for
line
in
lines
)
if
nrCommented
>=
len
(
lines
):
# Uncomment all lines
newText
=
"
\n
"
.
join
(
self
.
_uncommentLine
(
line
)
for
line
in
lines
)
selectedText
=
str
(
cursor
.
selectedText
())
if
selectedText
:
lines
=
selectedText
.
splitlines
()
if
(
adjustedEnd
>
adjustedStart
and
adjustedEnd
>
0
and
adjustedEnd
<=
len
(
text
)
and
text
[
adjustedEnd
-
1
]
in
"
\r\n
"
and
(
adjustedEnd
==
len
(
text
)
or
text
[
adjustedEnd
]
in
"
\r\n
"
)):
# Last empty line is not returned by selectedText()
# Explicitly add it.
lines
.
append
(
""
)
nrCommented
=
sum
(
1
if
self
.
_lineIsCommented
(
line
)
else
0
for
line
in
lines
)
if
nrCommented
>=
len
(
lines
)
and
lines
:
# Uncomment all lines
newText
=
"
\n
"
.
join
(
self
.
_uncommentLine
(
line
)
for
line
in
lines
)
else
:
# Comment all lines
newText
=
"
\n
"
.
join
(
self
.
_commentLine
(
line
)
for
line
in
lines
)
else
:
# Comment all lines
newText
=
"
\n
"
.
join
(
self
.
_commentLine
(
line
)
for
line
in
lines
)
newText
=
self
.
_commentLine
(
""
)
# Replace the selected text
cursor
.
insertText
(
newText
)
...
...
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