Skip to content

Commit 634dc97

Browse files
committed
editor: Support indenting lines which have only an unordered list marker
Refs #663.
1 parent 0080686 commit 634dc97

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

ReText/editor.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,25 @@ def getColor(colorName):
108108
return colorValues[colorName]
109109

110110
def documentIndentMore(document, cursor, globalSettings=globalSettings):
111+
if globalSettings.tabInsertsSpaces:
112+
indent = ' ' * globalSettings.tabWidth
113+
else:
114+
indent = '\t'
111115
if cursor.hasSelection():
112116
block = document.findBlock(cursor.selectionStart())
113117
end = document.findBlock(cursor.selectionEnd()).next()
114118
cursor.beginEditBlock()
115119
while block != end:
116120
cursor.setPosition(block.position())
117-
if globalSettings.tabInsertsSpaces:
118-
cursor.insertText(' ' * globalSettings.tabWidth)
119-
else:
120-
cursor.insertText('\t')
121+
cursor.insertText(indent)
121122
block = block.next()
122123
cursor.endEditBlock()
124+
return
125+
block = document.findBlock(cursor.position())
126+
unorderedListPattern = re.compile(r"^\s*[*-] $")
127+
if unorderedListPattern.match(block.text()):
128+
cursor.setPosition(block.position())
129+
cursor.insertText(indent)
123130
else:
124131
indent = globalSettings.tabWidth - (cursor.positionInBlock()
125132
% globalSettings.tabWidth)

tests/test_editor.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ def test_indentMoreWithSelection(self):
6969
self.assertEqual(' foo\n bar\nbaz',
7070
self.document.toPlainText())
7171

72+
def test_indentMoreInList(self):
73+
self.document.setPlainText('- one\n- ')
74+
cursor = QTextCursor(self.document)
75+
cursor.setPosition(8)
76+
documentIndentMore(self.document, cursor, self.settings)
77+
self.assertEqual('- one\n - ', self.document.toPlainText())
78+
79+
self.document.setPlainText('- one\n- ')
80+
cursor.setPosition(5)
81+
documentIndentMore(self.document, cursor, self.settings)
82+
self.assertEqual('- one \n- ', self.document.toPlainText())
83+
7284
def test_indentLess(self):
7385
self.document.setPlainText(' foo')
7486
cursor = QTextCursor(self.document)

0 commit comments

Comments
 (0)