From 7eae9cdba679fe5f124b9c2b7041b4dfd3181bd8 Mon Sep 17 00:00:00 2001 From: Inez Korczynski Date: Wed, 20 Jun 2012 21:23:19 -0700 Subject: [PATCH] Support for insertion in slugs. Change-Id: I8e144206520b59271edf854020b87ce947fe0559 --- modules/ve/ce/ve.ce.Surface.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js index cb635b9525..092d6b5069 100644 --- a/modules/ve/ce/ve.ce.Surface.js +++ b/modules/ve/ce/ve.ce.Surface.js @@ -18,6 +18,7 @@ ve.ce.Surface = function( $container, model ) { this.$document = $( document ); this.clipboard = {}; this.render = true; // Used in ve.ce.TextNode + this.sluggable = true; this.poll = { text: null, @@ -267,21 +268,32 @@ ve.ce.Surface.prototype.onKeyPress = function( e ) { var selection = this.model.getSelection(); - if ( selection.getLength() === 0 ) { - if ( this.hasSlugAtOffset( selection.start ) ) { + if ( + selection.getLength() === 0 && + this.sluggable === true && + this.hasSlugAtOffset( selection.start ) + ) { + var node; + this.sluggable = false; + this.stopPolling(); + if ( this.documentView.getNodeFromOffset( selection.start ).getLength() !== 0 ) { var data = [ { 'type' : 'paragraph' }, { 'type' : '/paragraph' } ]; - this.stopPolling(); this.model.change( ve.dm.Transaction.newFromInsertion( this.documentView.model, selection.start, data ), - new ve.Range ( selection.start + 1 ) + new ve.Range( selection.start + 1 ) ); - this.clearPollData(); - this.startPolling(); + node = this.documentView.getNodeFromOffset( selection.start + 1 ); + } else { + node = this.documentView.getNodeFromOffset( selection.start ); } + node.$.empty(); + node.$.append( document.createTextNode('') ); + this.clearPollData(); + this.startPolling(); } if ( selection.getLength() > 0 && e.which !== 0 ) { @@ -496,6 +508,7 @@ ve.ce.Surface.prototype.onContentChange = function( e ) { e.new.range ); } + this.sluggable = true; }; ve.ce.Surface.prototype.onChange = function( transaction, selection ) {