reworking multiline mode in editable field...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-03-30 12:58:23 +03:00
parent dd8fc05f13
commit 19b1a9b2c4

View File

@ -548,6 +548,16 @@ if(typeof(jQuery) != typeof(undefined)){
if(!that.prop('contenteditable')){ if(!that.prop('contenteditable')){
return return
} }
// XXX make this global...
var caretOffset = function(elem){
var range = window.getSelection().getRangeAt(0)
var preCaretRange = range.cloneRange()
preCaretRange.selectNodeContents(elem)
preCaretRange.setEnd(range.endContainer, range.endOffset)
return preCaretRange.toString().length || 0
}
var c = caretOffset(this)
evt.stopPropagation() evt.stopPropagation()
@ -565,6 +575,8 @@ if(typeof(jQuery) != typeof(undefined)){
that.trigger('edit-commit', that.text()) that.trigger('edit-commit', that.text())
// done -- multi-line... // done -- multi-line...
// XXX revise: do we exit on Enter or on ctrl-Enter???
// ...or should there be an option???
} else if(n == 'Enter' } else if(n == 'Enter'
&& (evt.ctrlKey || evt.metaKey) && (evt.ctrlKey || evt.metaKey)
&& options.multiline){ && options.multiline){
@ -572,6 +584,20 @@ if(typeof(jQuery) != typeof(undefined)){
that.trigger('edit-commit', that.text()) that.trigger('edit-commit', that.text())
// multi-line keep keys...
} else if(n == 'Enter' >= 0 && options.multiline){
return
// multi-line arrow keys -- keep key iff not at first/last position...
} else if(n == 'Up'
&& c > 0
&& options.multiline){
return
} else if(n == 'Down'
&& c < $(this).text().length
&& options.multiline){
return
// continue handling... // continue handling...
} else if(options.propagate_unhandled_keys !== false){ } else if(options.propagate_unhandled_keys !== false){
// NOTE: jQuery can't reuse browser events, this // NOTE: jQuery can't reuse browser events, this