Skip to content

Commit 3854df1

Browse files
authored
Merge pull request #239 from JunoLab/sp/resultclicks
improve mouse click handling in results
2 parents 0c22854 + 9a077b9 commit 3854df1

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

lib/editor/result-view.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,47 @@ export default class ResultView {
7979
}
8080
})
8181

82-
this.view.addEventListener('click', () => {
83-
if (!(this.overlayElement && this.overlayElement.parentNode)) return
84-
let edView
85-
if (edView = atom.views.getView(atom.workspace.getActiveTextEditor())) {
86-
edView.focus()
82+
this.view.addEventListener('mouseup', ev => {
83+
if (ev.button === 1) {
84+
// middle mouse button
85+
this.model.remove()
86+
this.focusEditor()
87+
} else if (document.getSelection().toString().length === 0) {
88+
this.focusEditor()
8789
}
8890
})
8991

92+
this.view.addEventListener('mousedown', ev => {
93+
this.blurEditor()
94+
})
95+
96+
this.view.addEventListener('mouseleave', ev => {
97+
this.focusEditor()
98+
})
99+
90100
if (fade) this.fadeIn()
91101
if (content != null) this.setContent(content, opts)
92102
if (loading) this.setContent(views.render(span('loading icon icon-gear')), opts)
93103

94104
return this.view
95105
}
96106

107+
blurEditor (ed) {
108+
const c = this.model.editor.component
109+
if (c && c.didBlurHiddenInput) {
110+
c.didBlurHiddenInput({
111+
relatedTarget: null
112+
})
113+
}
114+
}
115+
116+
focusEditor () {
117+
const c = this.model.editor.component
118+
if (c && c.didFocus) {
119+
c.didFocus()
120+
}
121+
}
122+
97123
fadeIn () {
98124
this.view.classList.add('ink-hide')
99125
setTimeout(() => this.view.classList.remove('ink-hide'), 20)

styles/ink.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ atom-text-editor {
196196
transition: all 0.2s, visibility 0s;
197197
opacity: 1;
198198
cursor: default;
199-
user-select: auto;
199+
user-select: text;
200200

201201
border-radius: 3px;
202202

0 commit comments

Comments
 (0)