Skip to content

Commit

Permalink
adds class SmartNewLineCommand
Browse files Browse the repository at this point in the history
fix issue when folded headline is last one  in file
  • Loading branch information
vovkkk committed Mar 26, 2013
1 parent 391f4d9 commit 0c68735
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
5 changes: 0 additions & 5 deletions Add Line SmartMarkdown Heading.sublime-macro

This file was deleted.

3 changes: 1 addition & 2 deletions Default (Linux).sublime-keymap
Expand Up @@ -23,8 +23,7 @@
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown" }
]
},
{ "keys": ["ctrl+enter"], "command": "run_macro_file",
"args": {"file": "res://Packages/SmartMarkdown/Add Line SmartMarkdown Heading.sublime-macro"}, "context":
{ "keys": ["ctrl+enter"], "command": "smart_new_line", "context":
[
{ "key": "selector", "operator": "equal", "operand": "markup.heading.markdown" }
]
Expand Down
3 changes: 1 addition & 2 deletions Default (OSX).sublime-keymap
Expand Up @@ -23,8 +23,7 @@
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown" }
]
},
{ "keys": ["ctrl+enter"], "command": "run_macro_file",
"args": {"file": "res://Packages/SmartMarkdown/Add Line SmartMarkdown Heading.sublime-macro"}, "context":
{ "keys": ["ctrl+enter"], "command": "smart_new_line", "context":
[
{ "key": "selector", "operator": "equal", "operand": "markup.heading.markdown" }
]
Expand Down
3 changes: 1 addition & 2 deletions Default (Windows).sublime-keymap
Expand Up @@ -23,8 +23,7 @@
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown" }
]
},
{ "keys": ["ctrl+enter"], "command": "run_macro_file",
"args": {"file": "res://Packages/SmartMarkdown/Add Line SmartMarkdown Heading.sublime-macro"}, "context":
{ "keys": ["ctrl+enter"], "command": "smart_new_line", "context":
[
{ "key": "selector", "operator": "equal", "operand": "markup.heading.markdown" }
]
Expand Down
15 changes: 15 additions & 0 deletions smart_folding.py
Expand Up @@ -24,6 +24,21 @@
HEADLINE_PATTERN = re.compile(r'^(#+)\s.*')


class SmartNewLineCommand(sublime_plugin.TextCommand):
"""Changes behavior of default 'insert line after'
Puts new line after folding mark if any.
"""
def run(self, edit):
self.view.run_command("move_to", { "to": "hardeol"})
self.view.run_command("move_to", { "to": "eol"})
point = self.view.full_line(self.view.sel()[0])
if headline._is_region_folded(point.b + 1, self.view):
self.view.run_command("move_to", { "to": "eof"})
self.view.run_command("insert", {"characters": "\n"})
else:
self.view.run_command("insert", {"characters": "\n"})


class SmartFoldingCommand(sublime_plugin.TextCommand):
"""Smart folding is used to fold / unfold headline at the point.
Expand Down

0 comments on commit 0c68735

Please sign in to comment.