Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze-editor/react-components",
"comment": "fix caret issue with PrefixElement",
"type": "patch"
}
],
"packageName": "@coze-editor/react-components",
"email": "stream-pipe@users.noreply.github.com"
}
2 changes: 1 addition & 1 deletion packages/text-editor/dev/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createRoot } from 'react-dom/client';
import Page from './pages/highlight';
import Page from './pages/prefix';
import './index.css';

createRoot(document.getElementById('app')!).render(<Page />);
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ function textRange(node: Text, from: number, to = from) {
return range;
}

function flattenRect(rect: Rect, left: boolean) {
const x = left ? rect.left : rect.right;
return { left: x, right: x, top: rect.top, bottom: rect.bottom };
}

function clientRectsFor(dom: Node) {
if (dom.nodeType == 3) {
return textRange(dom as Text, 0, dom.nodeValue!.length).getClientRects();
Expand All @@ -33,6 +28,6 @@ function clientRectsFor(dom: Node) {
}
}

export { flattenRect, clientRectsFor };
export { clientRectsFor };

export type { Rect };
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useHTMLElement, useLatest } from '@coze-editor/react-hooks';
import { useInjector } from '@coze-editor/react';
import { Decoration, EditorView, keymap, WidgetType } from '@codemirror/view';

import { clientRectsFor, flattenRect } from './dom';
import { clientRectsFor } from './dom';

class PrefixElementWidget extends WidgetType {
constructor(
Expand Down Expand Up @@ -43,7 +43,7 @@ class PrefixElementWidget extends WidgetType {
return null;
}
const style = window.getComputedStyle(dom.parentNode as HTMLElement);
const rect = flattenRect(rects[0], style.direction != 'rtl');
const rect = rects[0];
const lineHeight = parseInt(style.lineHeight);
if (rect.bottom - rect.top > lineHeight * 1.5) {
return {
Expand Down
Loading