Trim range when formatting so that it excludes leading/trailing spaces
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
7fa1214cf1
commit
ffa7ceb70e
3 changed files with 29 additions and 4 deletions
|
@ -18,6 +18,10 @@ import EditorModel from "./model";
|
|||
import DocumentPosition, {Predicate} from "./position";
|
||||
import {Part} from "./parts";
|
||||
|
||||
const whileSpacePredicate: Predicate = (index, offset, part) => {
|
||||
return part.text[offset] === " ";
|
||||
};
|
||||
|
||||
export default class Range {
|
||||
private _start: DocumentPosition;
|
||||
private _end: DocumentPosition;
|
||||
|
@ -35,6 +39,11 @@ export default class Range {
|
|||
});
|
||||
}
|
||||
|
||||
trim() {
|
||||
this._start = this._start.forwardsWhile(this.model, whileSpacePredicate);
|
||||
this._end = this._end.backwardsWhile(this.model, whileSpacePredicate);
|
||||
}
|
||||
|
||||
expandBackwardsWhile(predicate: Predicate) {
|
||||
this._start = this._start.backwardsWhile(this.model, predicate);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue