Prevent continuous deletion of a single line

This commit is contained in:
Matt Lott 2014-11-21 21:02:35 -08:00
parent 904d605e42
commit c012cd4e30
2 changed files with 33 additions and 0 deletions

View file

@ -6,8 +6,10 @@ CampaignList = require('views/play/WorldMapView').campaigns
options =
'default':
autocompleteFontSizePx: 16
backspaceThrottle: false
'dungeon':
autocompleteFontSizePx: 20
backspaceThrottle: true
module.exports = CampaignOptions =
getCampaignForSlug: (slug) ->

View file

@ -216,6 +216,37 @@ module.exports = class SpellView extends CocoView
name: 'disable-spaces'
bindKey: 'Space'
exec: => @ace.execCommand 'insertstring', ' ' unless LevelOptions[@options.level.get('slug')]?.disableSpaces
addCommand
name: 'throttle-backspaces'
bindKey: 'Backspace'
exec: =>
# Throttle the backspace speed
# Slow to 500ms when whitespace at beginning of line is first encountered
# Slow to 100ms for remaining whitespace at beginning of line
# Rough testing showed backspaces happen at 150ms when tapping.
# Backspace speed varies by system when holding, 30ms on fastest Macbook setting.
unless CampaignOptions?.getOption?(@options?.level?.get?('slug'), 'backspaceThrottle')
@ace.remove "left"
return
nowDate = Date.now()
if @aceSession.selection.isEmpty()
cursor = @ace.getCursorPosition()
line = @aceDoc.getLine(cursor.row)
if /^\s*$/.test line.substring(0, cursor.column)
@backspaceThrottleMs ?= 500
# console.log "SpellView @backspaceThrottleMs=#{@backspaceThrottleMs}"
# console.log 'SpellView lastBackspace diff', nowDate - @lastBackspace if @lastBackspace?
if not @lastBackspace? or nowDate - @lastBackspace > @backspaceThrottleMs
@backspaceThrottleMs = 100
@lastBackspace = nowDate
@ace.remove "left"
return
@backspaceThrottleMs = null
@lastBackspace = nowDate
@ace.remove "left"
fillACE: ->
@ace.setValue @spell.source