Permalink
Browse files

adds class SmartNewLineCommand

fix issue when folded headline is last one  in file
  • Loading branch information...
1 parent 391f4d9 commit 0c68735b32b675621733bb0dfb625beca52dd7ac @vovkkk vovkkk committed Mar 26, 2013
@@ -1,5 +0,0 @@
-[
- {"command": "move_to", "args": {"to": "hardeol"}},
- {"command": "move_to", "args": {"to": "eol"}},
- {"command": "insert", "args": {"characters": "\n"}}
-]
@@ -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" }
]
@@ -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" }
]
@@ -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" }
]
View
@@ -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.

0 comments on commit 0c68735

Please sign in to comment.