-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
3,677 additions
and
748 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ | |
|
||
export * from "./format"; | ||
export * from "./toDelta"; | ||
export * from "./utils"; | ||
export * from "./markListFactory"; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import { Skip, Transposed as T } from "./format"; | ||
import { extendAttachGroup, isAttachGroup, isObjMark, isSkipMark, tryExtendMark } from "./utils"; | ||
|
||
/** | ||
* Helper class for constructing an offset list of marks that... | ||
* - Does not insert offsets if there is no content after them | ||
* - Does not insert 0-sized offsets | ||
* - Merges runs of offsets together | ||
* - Merges marks together | ||
*/ | ||
export class MarkListFactory { | ||
private offset = 0; | ||
public readonly list: T.MarkList = []; | ||
|
||
public push(...marks: T.Mark[]): void { | ||
for (const item of marks) { | ||
if (isSkipMark(item)) { | ||
this.pushOffset(item); | ||
} else { | ||
this.pushContent(item); | ||
} | ||
} | ||
} | ||
|
||
public pushOffset(offset: Skip): void { | ||
this.offset += offset; | ||
} | ||
|
||
public pushContent(mark: T.ObjectMark): void { | ||
if (this.offset > 0) { | ||
this.list.push(this.offset); | ||
this.offset = 0; | ||
} | ||
const prev = this.list[this.list.length - 1]; | ||
if (isObjMark(prev)) { | ||
if (isAttachGroup(prev)) { | ||
if (isAttachGroup(mark)) { | ||
extendAttachGroup(prev, mark); | ||
return; | ||
} | ||
} else if ( | ||
!isAttachGroup(mark) | ||
&& prev.type === mark.type | ||
) { | ||
// Neither are attach groups | ||
if (tryExtendMark(prev, mark)) { | ||
return; | ||
} | ||
} | ||
} | ||
this.list.push(mark); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.