Browse files

Trim history entries. Use run_command paste.

  • Loading branch information...
1 parent ebb5e57 commit 7d57130a43b743a557edbd2a04c28b0085b54632 @kemayo kemayo committed Oct 2, 2011
Showing with 11 additions and 19 deletions.
  1. +1 −1 ClipboardHistory.sublime-settings
  2. +10 −18 clipboard.py
View
2 ClipboardHistory.sublime-settings
@@ -1,4 +1,4 @@
{
"limit": 30
- ,"add_on_paste": true
+ ,"paste_and_indent": true
}
View
28 clipboard.py
@@ -3,38 +3,30 @@
import sublime
import sublime_plugin
-# TODO: limit the size of this?
history = []
class ClipboardDisplayCommand(sublime_plugin.TextCommand):
def run(self, edit):
- print history
if not history:
return
- self.view.window().show_quick_panel(history, self.panel_done)
+ # sublime has been known to choke and die on really big clipboard
+ # items getting displayed in the quick panel. Also, the truncation
+ # it uses for stuff that long is basically unreadable. Ergo...
+ summary = [item.strip()[:100] for item in history]
+ self.view.window().show_quick_panel(summary, self.panel_done)
def panel_done(self, picked):
if 0 > picked < len(history):
return
s = sublime.load_settings("ClipboardHistory.sublime-settings")
- text = history[picked]
- edit = self.view.begin_edit()
- new_regions = []
- for region in self.view.sel():
- self.view.replace(edit, region, text)
- new_region = sublime.Region(region.begin() + len(text),
- region.end() + len(text))
- new_regions.append(new_region)
- self.view.sel().clear()
- for region in new_regions:
- self.view.sel().add(region)
- self.view.end_edit(edit)
-
- if s.get("add_on_paste"):
- sublime.set_clipboard(text)
+ sublime.set_clipboard(history[picked])
+ if s.get('paste_and_indent'):
+ self.view.run_command('paste_and_indent')
+ else:
+ self.view.run_command('paste')
# Here we see a cunning plan. We listen for a key, but never say we

0 comments on commit 7d57130

Please sign in to comment.