8000 Hide command input field better by jacekkopecky · Pull Request #777 · atom/vim-mode · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Apr 6, 2018. It is now read-only.

Hide command input field better #777

Merged
merged 4 commits into from
Aug 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/view-models/search-view-model.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class SearchViewModel extends ViewModel

update: (reverse) ->
if reverse
@view.editorContainer.classList.add('reverse-search-input')
@view.editorContainer.classList.remove('search-input')
@view.classList.add('reverse-search-input')
@view.classList.remove('search-input')
else
@view.editorContainer.classList.add('search-input')
@view.editorContainer.classList.remove('reverse-search-input')
@view.classList.add('search-input')
@view.classList.remove('reverse-search-input')
3 changes: 2 additions & 1 deletion lib/view-models/view-model.coffee
8000
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ VimNormalModeInputElement = require './vim-normal-mode-input-element'
class ViewModel
constructor: (@operation, opts={}) ->
{@editor, @vimState} = @operation
@view = new VimNormalModeInputElement().initialize(this, opts)
@view = new VimNormalModeInputElement().initialize(this, atom.views.getView(@editor), opts)
@editor.normalModeInputView = @view
@vimState. @view.remove()

Expand All @@ -13,6 +13,7 @@ class ViewModel
cancel: (view) ->
if @vimState.isOperatorPending()
@vimState.pushOperations(new Input(''))
delete @editor.normalModeInputView

class Input
constructor: (@characters) ->
Expand Down
25 changes: 12 additions & 13 deletions lib/view-models/vim-normal-mode-input-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@ class VimNormalModeInputElement extends HTMLDivElement
createdCallback: ->
@className = "normal-mode-input"

@editorContainer = document.createElement("div")
@editorContainer.className = "editor-container"

@appendChild(@editorContainer)

initialize: (@viewModel, opts = {}) ->
initialize: (@viewModel, @mainEditorElement, opts = {}) ->
if opts.class?
@editorContainer.classList.add(opts.class)

if opts.hidden
@editorContainer.style.height = "0px"
@classList.add(opts.class)

@editorElement = document.createElement "atom-text-editor"
@editorElement.classList.add('editor')
@editorElement.getModel().setMini(true)
@editorElement.setAttribute('mini', '')
@editorContainer.appendChild(@editorElement)
@appendChild(@editorElement)

@singleChar = opts.singleChar
@defaultText = opts.defaultText ? ''

@panel = atom.workspace.addBottomPanel(item: this, priority: 100)
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()
Expand Down Expand Up @@ -55,7 +51,10 @@ class VimNormalModeInputElement extends HTMLDivElement

removePanel: ->
atom.workspace.getActivePane().activate()
@panel.destroy()
if @panel?
@panel.destroy()
else
this.remove()

module.exports =
document.registerElement("vim-normal-mode-input"
Expand Down
7 changes: 4 additions & 3 deletions spec/operators-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ describe "Operators", ->
editor.normalModeInputView.editorElement.getModel().setText(key)

describe "cancelling operations", ->
it "does not throw an error even if no operation is pending", ->
it "throws an error when no operation is pending", ->
# cancel operation pushes an empty input operation
# doing this without a pending operation throws an exception
# doing this without a pending operation would throw an exception
expect(-> vimState.pushOperations(new Input(''))).toThrow()

it "cancels and cleans up properly", ->
# make sure normalModeInputView is created
keydown('/')
expect(vimState.isOperatorPending()).toBe true
editor.normalModeInputView.viewModel.cancel()

expect(vimState.isOperatorPending()).toBe false
expect(-> editor.normalModeInputView.viewModel.cancel()).not.toThrow()
expect(editor.normalModeInputView).toBe undefined

describe "the x keybinding", ->
describe "on a line with content", ->
Expand Down
3 changes: 3 additions & 0 deletions spec/spec-helper.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ getEditorElement = (callback) ->
element.addEventListener "keydown", (e) ->
atom.keymaps.handleKeyboardEvent(e)

# mock parent element for the text editor
document.createElement('html').appendChild(atom.views.getView(textEditor))

callback(element)

mockPlatform = (editorElement, platform) ->
Expand Down
3 changes: 0 additions & 3 deletions spec/text-objects-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ describe "TextObjects", ->
options.element ?= editorElement
helpers.keydown(key, options)

normalModeInputKeydown = (key, opts = {}) ->
editor.normalModeInputView.editorElement.getModel().setText(key)

describe "Text Object commands in normal mode not preceded by an operator", ->
beforeEach ->
vimState.activateNormalMode()
Expand Down
11 changes: 11 additions & 0 deletions styles/vim-mode.less
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
padding-left: 10px;
}

atom-panel.bottom.vim-hidden-normal-mode-input {
height: 1px;
width: 1px;
overflow: hidden;
border: none;
display: block;
position: fixed;
top: -1px;
left: -1px;
}

.block-cursor(@visibility: visible) {
border: 0;
background-color: @syntax-cursor-color;
Expand Down
0