Created
July 30, 2014 08:42
-
-
Save catrope/a231c9051434bb1cf119 to your computer and use it in GitHub Desktop.
Word break relocation hacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js | |
index 2a018af..e826ab4 100644 | |
--- a/modules/ve/ce/ve.ce.Surface.js | |
+++ b/modules/ve/ce/ve.ce.Surface.js | |
@@ -1636,8 +1636,52 @@ ve.ce.Surface.prototype.onContentChange = function ( node, previous, next ) { | |
next.range.start - nodeOffset - 1 | |
); | |
// Apply insertion annotations | |
- annotations = node.unicornAnnotations || this.model.getInsertionAnnotations(); | |
- ve.dm.Document.static.addAnnotationsToData( data, annotations ); | |
+ //annotations = node.unicornAnnotations || this.model.getInsertionAnnotations(); | |
+ //ve.dm.Document.static.addAnnotationsToData( data, annotations ); | |
+ | |
+ | |
+ // FIXME duplication | |
+ | |
+ // TODO verify variable substitutions | |
+ | |
+ if ( node.unicornAnnotations !== null ) { | |
+ // This CBN is unicorned. Use the stored annotations. | |
+ annotations = node.unicornAnnotations; | |
+ } else { | |
+ annotations = this.model.getInsertionAnnotations(); | |
+ } | |
+ if ( annotations.getLength() ) { | |
+ annotationsLeft = this.model.getDocument().data.getAnnotationsFromOffset( previous.range.start - lengthDiff ); | |
+ annotationsRight = this.model.getDocument().data.getAnnotationsFromOffset( previous.range.start ); | |
+ for ( i = 0, length = annotations.getLength(); i < length; i++ ) { | |
+ annotation = annotations.get( i ); | |
+ annotationIndex = annotations.getIndex( i ); | |
+ if ( annotation.constructor.static.splitOnWordbreak ) { | |
+ nextData = ve.splitClusters( next.text ); | |
+ dataString = new ve.dm.DataString( nextData ); | |
+ if ( | |
+ // if no annotation to the right, check for wordbreak | |
+ ( | |
+ !annotationsRight.containsIndex( annotationIndex ) && | |
+ unicodeJS.wordbreak.isBreak( dataString, previous.range.start - lengthDiff - nodeOffset ) | |
+ ) || | |
+ // if no annotation to the left, check for wordbreak | |
+ ( | |
+ !annotationsLeft.containsIndex( annotationIndex ) && | |
+ unicodeJS.wordbreak.isBreak( dataString, previous.range.start - nodeOffset ) | |
+ ) | |
+ ) { | |
+ annotations.removeAt( i ); | |
+ i--; | |
+ length--; | |
+ } | |
+ } | |
+ } | |
+ ve.dm.Document.static.addAnnotationsToData( data, annotations ); | |
+ } | |
+ | |
+ | |
+ // FIXME duplication above | |
this.incRenderLock(); | |
try { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment