mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
reworking multiline mode in editable field...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
dd8fc05f13
commit
19b1a9b2c4
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user