8
0
Просмотр исходного кода

Added removing matched string.

Maksymilian Barnaś 9 лет назад
Родитель
Сommit
5ac44f58af

+ 2 - 1
packages/ckeditor5-autoformat/src/autoformat.js

@@ -45,12 +45,13 @@ export default class Autoformat extends Feature {
 			// <p>## ^</p> -> <heading2>^</heading2> (two steps: executing heading command + removing the text prefix)
 			//
 			// After ctrl+z: <p>## ^</p> (so undo two steps)
-			new AutoformatEngine( editor, /^(#{1,3}) $/, ( batch, match ) => {
+			new AutoformatEngine( editor, /^(#{1,3}) $/, ( batch, match, range ) => {
 				// TODO The heading command may be reconfigured in the future to support a different number
 				// of headings. That option must be exposed somehow, because we need to know here whether the replacement
 				// can be done or not.
 
 				const headingLevel = match[ 1 ].length;
+				batch.remove( range );
 
 				// This part needs slightly changed HeadingCommand.
 				// TODO Commit change to ckeditor5-heading

+ 12 - 1
packages/ckeditor5-autoformat/src/autoformatengine.js

@@ -5,6 +5,8 @@
 
 import TreeWalker from '../engine/model/treewalker.js';
 import Position from '../engine/model/position.js';
+import Range from '../engine/model/range.js';
+import LivePosition from '../engine/model/liveposition.js';
 
 export default class AutoformatEngine {
 	/**
@@ -41,10 +43,19 @@ export default class AutoformatEngine {
 
 				const matched = result;
 
+				let lastPath = _getLastPathPart( currentValue.nextPosition.path );
+				let liveStartPosition = LivePosition.createFromParentAndOffset( currentValue.item.parent, lastPath + result.index );
+
 				editor.document.enqueueChanges( () => {
-					callback( batch, matched  );
+					const range = Range.createFromPositionAndShift( liveStartPosition, matched[ 0 ].length );
+
+					callback( batch, matched, range  );
 				} );
 			}
 		} );
 	}
 }
+
+function _getLastPathPart( path ) {
+	return path[ path.length - 1 ];
+}