diff --git a/app/assets/javascripts/app/lib/base/jquery.textmodule.js b/app/assets/javascripts/app/lib/base/jquery.textmodule.js index d5cd96838..3f9b8a483 100644 --- a/app/assets/javascripts/app/lib/base/jquery.textmodule.js +++ b/app/assets/javascripts/app/lib/base/jquery.textmodule.js @@ -95,6 +95,7 @@ } }, this )) + // reduce buffer, in case close it this.$element.on('keydown', $.proxy(function (e) { // backspace @@ -109,8 +110,8 @@ } }, this )) + // build buffer this.$element.on('keypress', $.proxy(function (e) { - var value = this.$element.text() console.log('BUFF', this.buffer, e.keyCode, String.fromCharCode(e.which) ) a = $.proxy(function() { @@ -119,6 +120,16 @@ return } + // enter + if ( e.keyCode === 13 ) { + return + } + + // arrow keys + if ( e.keyCode === 37 || e.keyCode === 38 || e.keyCode === 39 || e.keyCode === 40 ) { + return + } + // enter : if ( String.fromCharCode(e.which) === ':' ) { this.buffer = this.buffer + ':' @@ -234,7 +245,13 @@ } var range = sel.getRangeAt(0) var clone = range.cloneRange() - clone.setStart(range.startContainer, range.startOffset - this.buffer.length) + + // improve error handling + start = range.startOffset - this.buffer.length + if (start < 0) { + start = 0 + } + clone.setStart(range.startContainer, start) clone.setEnd(range.startContainer, range.startOffset) clone.deleteContents() this.buffer = '' diff --git a/test/browser/agent_ticket_actions_level5_test.rb b/test/browser/agent_ticket_actions_level5_test.rb index 06f537bea..89223bded 100644 --- a/test/browser/agent_ticket_actions_level5_test.rb +++ b/test/browser/agent_ticket_actions_level5_test.rb @@ -121,8 +121,9 @@ class AgentTicketActionLevel5Test < TestCase :css => 'a[href="#ticket/create"]', }, { - :execute => 'wait', - :value => 2, + :execute => 'watch_for', + :area => '.active [data-name="body"]', + :value => '', }, { :execute => 'set', @@ -138,6 +139,10 @@ class AgentTicketActionLevel5Test < TestCase :execute => 'sendkey', :value => [:arrow_down] }, + { + :execute => 'wait', + :value => 1, + }, { :execute => 'click', :css => '.active .shortcut > ul> li > a', @@ -301,6 +306,11 @@ class AgentTicketActionLevel5Test < TestCase :execute => 'sendkey', :value => [:arrow_down] }, + { + :where => :instance2, + :execute => 'wait', + :value => 3, + }, { :where => :instance2, :execute => 'click', @@ -337,6 +347,11 @@ class AgentTicketActionLevel5Test < TestCase :execute => 'sendkey', :value => [:arrow_down] }, + { + :where => :instance2, + :execute => 'wait', + :value => 1, + }, { :where => :instance2, :execute => 'click', @@ -363,6 +378,11 @@ class AgentTicketActionLevel5Test < TestCase :execute => 'sendkey', :value => [:arrow_down] }, + { + :where => :instance2, + :execute => 'wait', + :value => 10, + }, { :where => :instance2, :execute => 'click', @@ -447,6 +467,11 @@ class AgentTicketActionLevel5Test < TestCase :execute => 'sendkey', :value => [:arrow_down] }, + { + :where => :instance2, + :execute => 'wait', + :value => 1, + }, { :where => :instance2, :execute => 'click', @@ -503,6 +528,11 @@ class AgentTicketActionLevel5Test < TestCase :execute => 'sendkey', :value => [:arrow_down] }, + { + :where => :instance2, + :execute => 'wait', + :value => 1, + }, { :where => :instance2, :execute => 'click', @@ -519,9 +549,8 @@ class AgentTicketActionLevel5Test < TestCase :css => '.modal-content .js-submit', }, { - :where => :instance2, - :execute => 'wait', - :value => 4, + :execute => 'watch_for_disappear', + :area => '.modal', }, { :where => :instance2, @@ -545,6 +574,11 @@ class AgentTicketActionLevel5Test < TestCase :execute => 'sendkey', :value => [:arrow_down] }, + { + :where => :instance2, + :execute => 'wait', + :value => 1, + }, { :where => :instance2, :execute => 'click',