From 455f099b504ec07dd492ab31987ae05a6f6774c7 Mon Sep 17 00:00:00 2001 From: Ben Beltran Date: Mon, 28 Sep 2015 12:39:59 -0500 Subject: Adds atom packages --- .../lib/view-models/search-view-model.coffee | 8 +++ .../vim-mode/lib/view-models/view-model.coffee | 7 ++- .../vim-command-mode-input-element.coffee | 64 --------------------- .../vim-normal-mode-input-element.coffee | 66 ++++++++++++++++++++++ 4 files changed, 78 insertions(+), 67 deletions(-) delete mode 100644 atom/packages/vim-mode/lib/view-models/vim-command-mode-input-element.coffee create mode 100644 atom/packages/vim-mode/lib/view-models/vim-normal-mode-input-element.coffee (limited to 'atom/packages/vim-mode/lib/view-models') diff --git a/atom/packages/vim-mode/lib/view-models/search-view-model.coffee b/atom/packages/vim-mode/lib/view-models/search-view-model.coffee index 8787210..8e63fd2 100644 --- a/atom/packages/vim-mode/lib/view-models/search-view-model.coffee +++ b/atom/packages/vim-mode/lib/view-models/search-view-model.coffee @@ -40,3 +40,11 @@ class SearchViewModel extends ViewModel atom.beep() super(view) @vimState.pushSearchHistory(@view.value) + + update: (reverse) -> + if reverse + @view.classList.add('reverse-search-input') + @view.classList.remove('search-input') + else + @view.classList.add('search-input') + @view.classList.remove('reverse-search-input') diff --git a/atom/packages/vim-mode/lib/view-models/view-model.coffee b/atom/packages/vim-mode/lib/view-models/view-model.coffee index 9cc63e1..b9da169 100644 --- a/atom/packages/vim-mode/lib/view-models/view-model.coffee +++ b/atom/packages/vim-mode/lib/view-models/view-model.coffee @@ -1,10 +1,10 @@ -VimCommandModeInputElement = require './vim-command-mode-input-element' +VimNormalModeInputElement = require './vim-normal-mode-input-element' class ViewModel constructor: (@operation, opts={}) -> {@editor, @vimState} = @operation - @view = new VimCommandModeInputElement().initialize(this, opts) - @editor.commandModeInputView = @view + @view = new VimNormalModeInputElement().initialize(this, atom.views.getView(@editor), opts) + @editor.normalModeInputView = @view @vimState.onDidFailToCompose => @view.remove() confirm: (view) -> @@ -13,6 +13,7 @@ class ViewModel cancel: (view) -> if @vimState.isOperatorPending() @vimState.pushOperations(new Input('')) + delete @editor.normalModeInputView class Input constructor: (@characters) -> diff --git a/atom/packages/vim-mode/lib/view-models/vim-command-mode-input-element.coffee b/atom/packages/vim-mode/lib/view-models/vim-command-mode-input-element.coffee deleted file mode 100644 index 4fd0c52..0000000 --- a/atom/packages/vim-mode/lib/view-models/vim-command-mode-input-element.coffee +++ /dev/null @@ -1,64 +0,0 @@ -class VimCommandModeInputElement extends HTMLDivElement - createdCallback: -> - @className = "command-mode-input" - - @editorContainer = document.createElement("div") - @editorContainer.className = "editor-container" - - @appendChild(@editorContainer) - - initialize: (@viewModel, opts = {}) -> - if opts.class? - @editorContainer.classList.add(opts.class) - - if opts.hidden - @editorContainer.style.height = "0px" - - @editorElement = document.createElement "atom-text-editor" - @editorElement.classList.add('editor') - @editorElement.getModel().setMini(true) - @editorElement.setAttribute('mini', '') - @editorContainer.appendChild(@editorElement) - - @singleChar = opts.singleChar - @defaultText = opts.defaultText ? '' - - @panel = atom.workspace.addBottomPanel(item: this, priority: 100) - - @focus() - @handleEvents() - - this - - handleEvents: -> - if @singleChar? - @editorElement.getModel().getBuffer().onDidChange (e) => - @confirm() if e.newText - else - atom.commands.add(@editorElement, 'editor:newline', @confirm.bind(this)) - - atom.commands.add(@editorElement, 'core:confirm', @confirm.bind(this)) - atom.commands.add(@editorElement, 'core:cancel', @cancel.bind(this)) - atom.commands.add(@editorElement, 'blur', @cancel.bind(this)) - - confirm: -> - @value = @editorElement.getModel().getText() or @defaultText - @viewModel.confirm(this) - @removePanel() - - focus: -> - @editorElement.focus() - - cancel: (e) -> - @viewModel.cancel(this) - @removePanel() - - removePanel: -> - atom.workspace.getActivePane().activate() - @panel.destroy() - -module.exports = -document.registerElement("vim-command-mode-input" - extends: "div", - prototype: VimCommandModeInputElement.prototype -) diff --git a/atom/packages/vim-mode/lib/view-models/vim-normal-mode-input-element.coffee b/atom/packages/vim-mode/lib/view-models/vim-normal-mode-input-element.coffee new file mode 100644 index 0000000..2371753 --- /dev/null +++ b/atom/packages/vim-mode/lib/view-models/vim-normal-mode-input-element.coffee @@ -0,0 +1,66 @@ +class VimNormalModeInputElement extends HTMLDivElement + createdCallback: -> + @className = "normal-mode-input" + + initialize: (@viewModel, @mainEditorElement, opts = {}) -> + if opts.class? + @classList.add(opts.class) + + @editorElement = document.createElement "atom-text-editor" + @editorElement.classList.add('editor') + @editorElement.getModel().setMini(true) + @editorElement.setAttribute('mini', '') + @appendChild(@editorElement) + + @singleChar = opts.singleChar + @defaultText = opts.defaultText ? '' + + if opts.hidden + @classList.add('vim-hidden-normal-mode-input') + @mainEditorElement.parentNode.appendChild(this) + else + @panel = atom.workspace.addBottomPanel(item: this, priority: 100) + + @focus() + @handleEvents() + + this + + handleEvents: -> + if @singleChar? + compositing = false + @editorElement.getModel().getBuffer().onDidChange (e) => + @confirm() if e.newText and not compositing + @editorElement.addEventListener 'compositionstart', -> compositing = true + @editorElement.addEventListener 'compositionend', -> compositing = false + else + atom.commands.add(@editorElement, 'editor:newline', @confirm.bind(this)) + + atom.commands.add(@editorElement, 'core:confirm', @confirm.bind(this)) + atom.commands.add(@editorElement, 'core:cancel', @cancel.bind(this)) + atom.commands.add(@editorElement, 'blur', @cancel.bind(this)) + + confirm: -> + @value = @editorElement.getModel().getText() or @defaultText + @viewModel.confirm(this) + @removePanel() + + focus: -> + @editorElement.focus() + + cancel: (e) -> + @viewModel.cancel(this) + @removePanel() + + removePanel: -> + atom.workspace.getActivePane().activate() + if @panel? + @panel.destroy() + else + this.remove() + +module.exports = +document.registerElement("vim-normal-mode-input" + extends: "div", + prototype: VimNormalModeInputElement.prototype +) -- cgit