mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-28 15:03:57 -04:00
Prevent continuous deletion of a single line
This commit is contained in:
parent
904d605e42
commit
c012cd4e30
2 changed files with 33 additions and 0 deletions
app
|
@ -6,8 +6,10 @@ CampaignList = require('views/play/WorldMapView').campaigns
|
||||||
options =
|
options =
|
||||||
'default':
|
'default':
|
||||||
autocompleteFontSizePx: 16
|
autocompleteFontSizePx: 16
|
||||||
|
backspaceThrottle: false
|
||||||
'dungeon':
|
'dungeon':
|
||||||
autocompleteFontSizePx: 20
|
autocompleteFontSizePx: 20
|
||||||
|
backspaceThrottle: true
|
||||||
|
|
||||||
module.exports = CampaignOptions =
|
module.exports = CampaignOptions =
|
||||||
getCampaignForSlug: (slug) ->
|
getCampaignForSlug: (slug) ->
|
||||||
|
|
|
@ -216,6 +216,37 @@ module.exports = class SpellView extends CocoView
|
||||||
name: 'disable-spaces'
|
name: 'disable-spaces'
|
||||||
bindKey: 'Space'
|
bindKey: 'Space'
|
||||||
exec: => @ace.execCommand 'insertstring', ' ' unless LevelOptions[@options.level.get('slug')]?.disableSpaces
|
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: ->
|
fillACE: ->
|
||||||
@ace.setValue @spell.source
|
@ace.setValue @spell.source
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue