Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions packages/adapter/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class SylApi {
// `length` refers to the length of the text
public getText(range?: Types.IRangeStatic) {
try {
const doc = this.view.state.doc;
const { doc } = this.view.state;
let from = 0;
let to = doc.nodeSize - 2;
let length;
Expand All @@ -181,17 +181,24 @@ class SylApi {
node.content.forEach(_node => {
if (startPos > from || startPos + _node.nodeSize > from) {
let text: string = _node.isText ? _node.textContent : _node.type.spec.getText ? _node.attrs.text : '';
if (startPos < from) text = text.substr(from - startPos);
if (startPos < from) {
text = text.slice(from - startPos);
} else {
if (startPos > to) {
return;
}
text = text.slice(0, Math.min(to - startPos, text.length));
}
textRes += text;
}
startPos += _node.nodeSize;
});
}
});
return textRes.substr(0, length);
} catch (e) {
console.error(e);
this.onError(e, arguments);
return textRes.slice(0, length);
} catch (err) {
console.error(err);
this.onError(err, arguments);
return '';
}
}
Expand Down