From 299c77db84841c1af30a61a64f721ccd0d4a812f Mon Sep 17 00:00:00 2001 From: Inez Korczynski Date: Fri, 16 Mar 2012 22:16:15 +0000 Subject: [PATCH] Make LinkInspector works (using annotate method in SurfaceView) --- modules/ve/ce/ve.ce.Surface.js | 7 +++-- .../ve/ui/inspectors/ve.ui.LinkInspector.js | 29 +++++-------------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js index 1570717c05..67b1c837b1 100644 --- a/modules/ve/ce/ve.ce.Surface.js +++ b/modules/ve/ce/ve.ce.Surface.js @@ -115,7 +115,7 @@ ve.ce.Surface = function( $container, model ) { /* Methods */ ve.ce.Surface.prototype.annotate = function( method, annotation ) { - var range = this.getSelectionRange(), + var range = this.currentSelection, _this = this; if ( method === 'toggle' ) { @@ -511,8 +511,9 @@ ve.ce.Surface.prototype.onKeyDown = function( e ) { }; ve.ce.Surface.prototype.getOffset = function( elem, offset, global ) { - var $leafNode = this.getLeafNode( elem ), - current = [$leafNode.contents(), 0], + var $leafNode = this.getLeafNode( elem ); + if($leafNode === null)return; + var current = [$leafNode.contents(), 0], stack = [current], localOffset = 0; diff --git a/modules/ve/ui/inspectors/ve.ui.LinkInspector.js b/modules/ve/ui/inspectors/ve.ui.LinkInspector.js index f1d79305e7..5e8121b9d8 100644 --- a/modules/ve/ui/inspectors/ve.ui.LinkInspector.js +++ b/modules/ve/ui/inspectors/ve.ui.LinkInspector.js @@ -22,14 +22,10 @@ ve.ui.LinkInspector = function( toolbar, context ) { if ( $(this).is( '.es-inspector-button-disabled' ) ) { return; } - var surfaceView = _this.context.getSurfaceView(), - surfaceModel = surfaceView.getModel(), - tx = surfaceModel.getDocument().prepareContentAnnotation( - surfaceView.currentSelection, - 'clear', - /link\/.*/ - ); - surfaceModel.transact( tx ); + + var surfaceView = _this.context.getSurfaceView(); + surfaceView.annotate( 'clear', /link\/.*/ ); + _this.$locationInput.val( '' ); _this.context.closeInspector(); } ); @@ -86,20 +82,9 @@ ve.ui.LinkInspector.prototype.onClose = function( accept ) { if ( title === this.getTitleFromSelection() || !title ) { return; } - var surfaceView = this.context.getSurfaceView(), - surfaceModel = surfaceView.getModel(); - var clear = surfaceModel.getDocument().prepareContentAnnotation( - surfaceView.currentSelection, - 'clear', - /link\/.*/ - ); - surfaceModel.transact( clear ); - var set = surfaceModel.getDocument().prepareContentAnnotation( - surfaceView.currentSelection, - 'set', - { 'type': 'link/internal', 'data': { 'title': title } } - ); - surfaceModel.transact( set ); + var surfaceView = this.context.getSurfaceView(); + surfaceView.annotate( 'clear', /link\/.*/ ); + surfaceView.annotate( 'set', { 'type': 'link/internal', 'data': { 'title': title } } ); } };