Skip to content
Closed
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
Expand Up @@ -203,7 +203,7 @@ export default function GraphicalEditor(props: IGraphicalEditorProps) {
}, [props.targetPath]);

const syncCurrentLine = useCallback(() => {
const lineNumber = editorLineHolder.getSceneLine(props.targetPath) || 1;
const lineNumber = editorLineHolder.getSceneLineOrFirstLine(props.targetPath);
EditorPreviewClient.sendSyncScene({
scenePath: props.targetPath,
lineNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default function TextEditor(props: ITextEditorProps) {
}, 500), []);

const syncCurrentLine = useCallback(() => {
const lineNumber = editorLineHolder.getSceneLine(props.targetPath) || editorRef.current?.getPosition()?.lineNumber || 1;
const lineNumber = editorLineHolder.getSceneLineOrFirstLine(props.targetPath);
EditorPreviewClient.sendSyncScene({
scenePath: target?.path ?? '',
Comment on lines +135 to 137

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

syncCurrentLine 中,scenePath 使用了 target?.path。这与 GraphicalEditor 的实现不一致,且在多编辑器实例并存(如多页签模式)的情况下,可能会导致非活跃状态的编辑器在响应同步事件时,将自身的行号数据同步到当前活跃页面的路径上,从而引发预览错乱。建议统一使用 props.targetPath 以确保同步路径的准确性。

Suggested change
const lineNumber = editorLineHolder.getSceneLineOrFirstLine(props.targetPath);
EditorPreviewClient.sendSyncScene({
scenePath: target?.path ?? '',
const lineNumber = editorLineHolder.getSceneLineOrFirstLine(props.targetPath);
EditorPreviewClient.sendSyncScene({
scenePath: props.targetPath,

lineNumber,
Expand Down
7 changes: 6 additions & 1 deletion packages/origine2/src/runtime/WG_ORIGINE_RUNTIME.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const lspSceneName = {value: ""};

class EditorLineHolder{
private mapSceneUrlToSentence = new Map<string,Position>();

public recordSceneEditingLine(sceneUrl: string, lineNumber: number) {
this.mapSceneUrlToSentence.set(sceneUrl, new Position(lineNumber, 0));
// console.log(this.mapSceneUrlToSentence);
Expand All @@ -25,6 +25,11 @@ class EditorLineHolder{
return this.mapSceneUrlToSentence.get(sceneUrl)?.lineNumber ?? 0;
}

public getSceneLineOrFirstLine(sceneUrl: string): number {
const lineNumber = this.getSceneLine(sceneUrl);
return lineNumber > 0 ? lineNumber : 1;
}

public getScenePosition(sceneUrl: string): Position {
return this.mapSceneUrlToSentence.get(sceneUrl) ?? new Position(0, 0);
}
Expand Down
Loading