Skip to content

Commit

Permalink
🐛 fix #262
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Apr 2, 2020
1 parent 2b7880a commit af95e01
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

### v3.0.8 / 2020-04-0x

* [262](https://github.com/Vanessa219/vditor/issues/262) ctrl+m... delete, and enter `修复缺陷`
* [260](https://github.com/Vanessa219/vditor/issues/260) Not working typewritermode at code block `修复缺陷`

### v3.0.7 / 2020-04-01
Expand Down
2 changes: 1 addition & 1 deletion src/ts/util/fixBrowserBehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ export const fixTable = (vditor: IVditor, event: KeyboardEvent, range: Range) =>
&& range.startOffset === 0 && range.toString() === "") {
const previousCellElement = goPreviousCell(cellElement, range, false);
if (!previousCellElement && tableElement) {
tableElement.outerHTML = `<p data-block="0"><wbr>${tableElement.textContent}</p>`;
tableElement.outerHTML = `<p data-block="0"><wbr>${tableElement.textContent.trim()}</p>`;
setRangeByWbr(vditor[vditor.currentMode].element, range);
execAfterRender(vditor);
}
Expand Down
7 changes: 6 additions & 1 deletion src/ts/util/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ export const getCursorPosition = (editor: HTMLElement) => {
children[range.startOffset].getClientRects().length > 0) {
// markdown 模式回车
cursorRect = children[range.startOffset].getClientRects()[0];
} else {
} else if (range.startContainer.childNodes.length > 0) {
// in table or code block
range.selectNode(range.startContainer.childNodes[Math.max(0, range.startOffset - 1)])
cursorRect = range.getClientRects()[0];
range.collapse(false);
} else {
cursorRect = (range.startContainer as HTMLElement).getClientRects()[0];
}
if (!cursorRect) {
let parentElement = range.startContainer.childNodes[range.startOffset] as HTMLElement;
Expand Down Expand Up @@ -169,6 +171,9 @@ export const setRangeByWbr = (element: HTMLElement, range: Range) => {
if (wbrElement.previousSibling) {
// text<wbr>
range.setStart(wbrElement.previousSibling, wbrElement.previousSibling.textContent.length);
} else if (wbrElement.nextSibling) {
// <wbr>text
range.setStart(wbrElement.nextSibling, 0);
} else {
// 内容为空
range.setStart(wbrElement.parentElement, 0);
Expand Down

0 comments on commit af95e01

Please sign in to comment.