editor: Add tab alignment command
This commit is contained in:
parent
cd88668f17
commit
9cd9fff96c
3 changed files with 28 additions and 8 deletions
|
|
@ -425,6 +425,22 @@ class Editor:
|
||||||
if empty_selection:
|
if empty_selection:
|
||||||
self.delete_character()
|
self.delete_character()
|
||||||
|
|
||||||
|
def tab_align(self):
|
||||||
|
if self.cursor_y == 0:
|
||||||
|
return
|
||||||
|
self.jump_to_start_of_line()
|
||||||
|
self.cursor_up()
|
||||||
|
while self._current_character() == " ":
|
||||||
|
self.cursor_right()
|
||||||
|
indent = self.cursor_x
|
||||||
|
self.cursor_down()
|
||||||
|
self.jump_to_start_of_line()
|
||||||
|
self.set_mark()
|
||||||
|
while self._current_character() == " ":
|
||||||
|
self.cursor_right()
|
||||||
|
self.delete_selection()
|
||||||
|
self.insert_text(" " * indent)
|
||||||
|
|
||||||
def join_lines(self):
|
def join_lines(self):
|
||||||
if self.cursor_y == 0:
|
if self.cursor_y == 0:
|
||||||
self.jump_to_start_of_line()
|
self.jump_to_start_of_line()
|
||||||
|
|
@ -564,7 +580,7 @@ class Editor:
|
||||||
terminal.ALT_H: highlight_block, terminal.CTRL_R: syntax_highlight_all,
|
terminal.ALT_H: highlight_block, terminal.CTRL_R: syntax_highlight_all,
|
||||||
terminal.CTRL_L: center_cursor, terminal.ALT_SEMICOLON: comment_highlighted,
|
terminal.CTRL_L: center_cursor, terminal.ALT_SEMICOLON: comment_highlighted,
|
||||||
terminal.ALT_c: cycle_syntax_highlighting, terminal.CTRL_X: prefix, terminal.ESC: quit,
|
terminal.ALT_c: cycle_syntax_highlighting, terminal.CTRL_X: prefix, terminal.ESC: quit,
|
||||||
terminal.CTRL_C: ctrl_c, terminal.CTRL_K: delete_line}
|
terminal.CTRL_C: ctrl_c, terminal.CTRL_K: delete_line, terminal.TAB: tab_align}
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -18,4 +18,4 @@ setup(name="diff-edit",
|
||||||
entry_points={"console_scripts": ["diff-edit=diff_edit:main"]},
|
entry_points={"console_scripts": ["diff-edit=diff_edit:main"]},
|
||||||
install_requires=[
|
install_requires=[
|
||||||
"pygments==2.10.0", "docopt==0.6.2",
|
"pygments==2.10.0", "docopt==0.6.2",
|
||||||
"fill3 @ git+https://github.com/ahamilton/eris@v2022.01.07#subdirectory=fill3"])
|
"fill3 @ git+https://github.com/ahamilton/eris@v2022.01.08#subdirectory=fill3"])
|
||||||
|
|
|
||||||
|
|
@ -144,23 +144,27 @@ class EditorTestCase(unittest.TestCase):
|
||||||
(self.editor.page_down, text, (0, 3)), (self.editor.page_down, text, (0, 3))])
|
(self.editor.page_down, text, (0, 3)), (self.editor.page_down, text, (0, 3))])
|
||||||
|
|
||||||
def test_join_lines(self):
|
def test_join_lines(self):
|
||||||
text = " \nab- \n -cd "
|
self._set_editor(" \nab- \n -cd ", (4, 2))
|
||||||
self._set_editor(text, (4, 2))
|
|
||||||
self._assert_changes([(self.editor.join_lines, " \nab- -cd ", (3, 1)),
|
self._assert_changes([(self.editor.join_lines, " \nab- -cd ", (3, 1)),
|
||||||
(self.editor.join_lines, "ab- -cd ", (0, 0)),
|
(self.editor.join_lines, "ab- -cd ", (0, 0)),
|
||||||
(self.editor.join_lines, "ab- -cd ", (0, 0))])
|
(self.editor.join_lines, "ab- -cd ", (0, 0))])
|
||||||
|
|
||||||
def test_delete_line(self):
|
def test_delete_line(self):
|
||||||
text = "a \ndef"
|
self._set_editor("a \ndef", (1, 0))
|
||||||
self._set_editor(text, (1, 0))
|
|
||||||
self._assert_changes([(self.editor.delete_line, "adef", (1, 0)),
|
self._assert_changes([(self.editor.delete_line, "adef", (1, 0)),
|
||||||
(self.editor.delete_line, "a", (1, 0))])
|
(self.editor.delete_line, "a", (1, 0))])
|
||||||
text = "\nabc"
|
self._set_editor("\nabc", (0, 0))
|
||||||
self._set_editor(text, (0, 0))
|
|
||||||
self._assert_changes([(self.editor.delete_line, "abc", (0, 0)),
|
self._assert_changes([(self.editor.delete_line, "abc", (0, 0)),
|
||||||
(self.editor.delete_line, "", (0, 0)),
|
(self.editor.delete_line, "", (0, 0)),
|
||||||
(self.editor.delete_line, "", (0, 0))])
|
(self.editor.delete_line, "", (0, 0))])
|
||||||
|
|
||||||
|
def test_tab_align(self):
|
||||||
|
text = " a\n b"
|
||||||
|
self._set_editor(text, (0, 0))
|
||||||
|
self._assert_changes([(self.editor.tab_align, text, (0, 0)),
|
||||||
|
(self.editor.cursor_down, text, (0, 1)),
|
||||||
|
(self.editor.tab_align, " a\n b", (1, 1))])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue