-
|
I am trying to make a custom autoformatter that autoformats LaTeX, it does this by replacing some text range for a latex embed. class AutoFormatLatex extends AutoFormat {
const AutoFormatLatex();
@override
AutoFormatResult? apply(
ParchmentDocument document,
int position,
String data,
) {
...
// The range i finally derive is valid, i left out some code
final debugText = document.toPlainText();
print(debugText); //prints "Testing $latex$"
print(
debugText.substring(
startIndex,
startIndex + contentLength,
),
); //prints "$latex$"
final change = Delta()
..retain(startIndex)
..delete(contentLength)
..insert(
EmbeddableObject(
'math',
inline: true,
data: {'formula': candidate.substring(firstIndex + 1)},
),
);
final undo = change.invert(documentDelta);
document.compose(change, .local);
return AutoFormatResult(
change: change,
undo: undo,
undoPositionCandidate: firstIndex + 1,
selection: TextSelection.collapsed(offset: firstIndex + 1),
undoSelection: TextSelection.collapsed(offset: position),
);
}
}For the design of this formatter i took some inspiration from the If i wrap the These are errors i am getting: If someone could help or suggest a different way to do this it would be much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
I was able to solve my issue (right after making the post, as usual) by using document.replace instead of document.compose. |
Beta Was this translation helpful? Give feedback.
I was able to solve my issue (right after making the post, as usual) by using document.replace instead of document.compose.