Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Switching between hide window and clear input when pressing 'escape' key #409

Merged
merged 5 commits into from
Nov 29, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/ui/dispatcher.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ handle 'togglemenu', ->
mainWindow = remote.getCurrentWindow()
if mainWindow.isMenuBarVisible() then mainWindow.setMenuBarVisibility(false) else mainWindow.setMenuBarVisibility(true)

handle 'setescapeclearsinput', (value) ->
viewstate.setEscapeClearsInput(value)

handle 'togglehidedockicon', ->
viewstate.setHideDockIcon(not viewstate.hidedockicon)

Expand Down
7 changes: 6 additions & 1 deletion src/ui/models/viewstate.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = exp = {
fontSize: localStorage.fontSize or 'medium'
zoom: tryparse(localStorage.zoom ? "1.0")
loggedin: false
escapeClearsInput: tryparse(localStorage.escapeClearsInput) or false
showtray: tryparse(localStorage.showtray) or false
hidedockicon: tryparse(localStorage.hidedockicon) or false
startminimizedtotray: tryparse(localStorage.startminimizedtotray) or false
Expand Down Expand Up @@ -138,7 +139,7 @@ module.exports = exp = {
action 'settyping', STOPPED
, 6000
, 6000

setShowConvMin: (doshow) ->
return if @showConvMin == doshow
@showConvMin = localStorage.showConvMin = doshow
Expand Down Expand Up @@ -191,6 +192,10 @@ module.exports = exp = {
document.querySelector('html').classList.add(localStorage.colorScheme)
document.querySelector('html').classList.add(fontsize)

setEscapeClearsInput: (value) ->
@escapeClearsInput = localStorage.escapeClearsInput = value
updated 'viewstate'

setShowTray: (value) ->
@showtray = localStorage.showtray = value

Expand Down
10 changes: 9 additions & 1 deletion src/ui/views/input.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ module.exports = view (models) ->
unless isModifierKey(e)
if e.keyCode == 27
e.preventDefault()
action 'hideWindow'
if models.viewstate.showtray && !models.viewstate.escapeClearsInput
action 'hideWindow'
else
# must focus on field and then execute:
# - select all text in input
# - replace them with an empty string
document.getElementById("message-input").focus()
document.execCommand("selectAll", false)
document.execCommand("insertText", false, "")
if e.keyCode == 13
e.preventDefault()
if models.viewstate.convertEmoji
Expand Down
18 changes: 18 additions & 0 deletions src/ui/views/menu.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,24 @@ templateView = (viewstate) ->
enabled: not viewstate.hidedockicon
checked: viewstate.showtray
click: -> action 'toggleshowtray'
}, {
label: 'Escape key behavior'
submenu: [
{
label: 'Hides window'
type: 'radio'
enabled: viewstate.showtray
checked: viewstate.showtray && !viewstate.escapeClearsInput
click: -> action 'setescapeclearsinput', false
}
{
label: 'Clears input' + if !viewstate.showtray then ' (default when tray is not showing)' else ''
type: 'radio'
enabled: viewstate.showtray
checked: !viewstate.showtray || viewstate.escapeClearsInput
click: -> action 'setescapeclearsinput', true
}
]
}
if isDarwin
{
Expand Down