Skip to content

Commit b00e7fc

Browse files
committed
Sigmund: fix indentation and selection
1 parent c37659f commit b00e7fc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pyqt_code_editor/components/sigmund.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,20 @@ def language(self):
5959
def get(self):
6060
text_cursor = self._editor.textCursor()
6161
if text_cursor.hasSelection():
62+
# Move to the start of the first selected block
63+
start = text_cursor.selectionStart()
64+
end = text_cursor.selectionEnd()
65+
text_cursor.setPosition(start)
66+
text_cursor.movePosition(text_cursor.StartOfBlock)
67+
text_cursor.setPosition(end, text_cursor.KeepAnchor)
68+
text_cursor.movePosition(text_cursor.EndOfBlock, text_cursor.KeepAnchor)
69+
self._editor.setTextCursor(text_cursor)
6270
content = self._normalize_line_breaks(text_cursor.selectedText())
6371
else:
6472
content = self._editor.toPlainText()
6573
self._indentation = self._get_indentation(content)
66-
logger.info(f'content was indented by "{self._indentation}"')
67-
return content, self._editor.code_editor_language
74+
logger.info(f'content was indented by "{self._indentation}"')
75+
return textwrap.dedent(content), self._editor.code_editor_language
6876

6977
def set(self, content, language):
7078
text_cursor = self._editor.textCursor()

0 commit comments

Comments
 (0)