Skip to content

Commit

Permalink
implement external cmdline + pasting in cmdline
Browse files Browse the repository at this point in the history
  • Loading branch information
lunixbochs committed Nov 16, 2017
1 parent dd6f29c commit 4c20a77
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
15 changes: 13 additions & 2 deletions actual.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .edit import Edit
from . import settings

class ActualSkipCmd(sublime_plugin.TextCommand): pass

class ActualEnable(sublime_plugin.ApplicationCommand):
def is_enabled(self):
Expand Down Expand Up @@ -114,10 +115,20 @@ def on_post_save_async(self, view):
# to prevent inconsistent updates
# then force a copy afterwards
def on_text_command(self, view, name, args):
v = ActualVim.get(view, create=False)
v = ActualVim.get(view, exact=False, create=False)
if not v:
return

if name == 'paste' and view.window().active_panel() == 'input' and v.cmd_panel:
tmp = []
for c in sublime.get_clipboard():
if c == '\n':
tmp.append('<cr>')
break
tmp.append(c)
v.press(''.join(tmp))
return ('actual_skip_cmd', {})

if name == 'drag_select':
v.drag_select = args.get('by')

Expand All @@ -128,7 +139,7 @@ def on_window_command(self, view, name, args):
self.on_text_command(view, name, args)

def on_post_text_command(self, view, name, args):
v = ActualVim.get(view, create=False)
v = ActualVim.get(view, exact=False, create=False)
if not v:
return

Expand Down
9 changes: 8 additions & 1 deletion neo.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ def _setup(self):
self._sem.acquire()

# set up UI (before anything else so we can see errors)
options = {'popupmenu_external': True, 'rgb': True}
options = {
'ext_popupmenu': True,
'ext_cmdline': True,
'rgb': True,
}
self.nv.ui_attach(self.width, self.height, options)

# hidden buffers allow us to multiplex them
Expand Down Expand Up @@ -197,6 +201,9 @@ def on_notification(method, data):
self.av.on_bell()
elif name in ('popupmenu_show', 'popupmenu_hide', 'popupmenu_select'):
self.av.on_popupmenu(name, args)
elif name in ('cmdline_show', 'cmdline_pos', 'cmdline_special_char', 'cmdline_hide',
'cmdline_block_show', 'cmdline_block_append', 'cmdline_block_hide'):
self.av.on_cmdline(name, args)
vim.screen.redraw(data)
if self.av:
self.av.on_redraw(data, vim.screen)
Expand Down
53 changes: 53 additions & 0 deletions view.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def __init__(self, view):
self.keyq = queue.Queue()

self.view = view
self.cmd_panel = None
self.cmd_text = None
self.cmd_lock = threading.Lock()

self.last_sel = None
self.buf = None
self.sub_changes = None
Expand All @@ -54,6 +58,7 @@ def __init__(self, view):
self.last_size = None
self.block = False
self.block_hit = False
self.nosync = False

# settings are marked here when applying mode-specific settings, and erased after
self.tmpsettings = []
Expand Down Expand Up @@ -337,6 +342,8 @@ def sync_to_vim(self, force=False):

def sync_from_vim(self, edit=None):
if not self.actual: return
if self.nosync:
return

def update(view, edit):
with self.busy:
Expand Down Expand Up @@ -595,6 +602,51 @@ def render(update=False):
self.popup['selected'] = args[0][0]
render(update=True)

def on_cmdline(self, cmd, args):
with self.cmd_lock:
window = self.view.window()
if cmd == 'cmdline_show':
content, pos, firstc, prompt, indent, level = args[0]
text = content[0][1]

def on_done(s):
self.nosync = False
with self.update_lock:
self.update_needed += 1
def onready():
sublime.set_timeout(self.update, 0)
_, ready = neo.vim.press('<cr>', onready)
if ready: self.update()

def on_cancel():
if self.cmd_panel:
self.press('<esc>')

text = firstc + text
panel = self.cmd_panel
if panel:
if text != self.cmd_text:
with Edit(panel) as edit:
edit.replace(sublime.Region(0, panel.size()), text)
self.cmd_text = text
else:
panel = window.show_input_panel(prompt, text, on_done, None, on_cancel)
self.nosync = True
s = panel.settings()
s.set('av_input', True)
s.set('actual_mode', True)
_views[panel.id()] = self
self.cmd_panel = panel
elif cmd == 'cmdline_hide':
self.nosync = False
panel = self.cmd_panel
if panel:
self.cmd_panel = None
self.cmd_text = None
_views.pop(panel.id(), None)
if window.active_panel() == 'input':
window.run_command('hide_panel', {'cancel': True})

def on_write(self):
self.view.run_command('save')

Expand Down Expand Up @@ -678,6 +730,7 @@ def on_redraw(self, data, screen):
self.screen_changes = screen.changes
hl = screen.highlights()
sublime.set_timeout(lambda: self.highlight(hl), 0)
self.status_from_vim()

def on_appcmd(self, cmd, args): sublime.run_command(cmd, args or {})
def on_wincmd(self, cmd, args): self.view.window().run_command(cmd, args or {})
Expand Down

0 comments on commit 4c20a77

Please sign in to comment.