Visual editor ignores changes made to its file outside it while it has focus

オープン
#1,236 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
typescript

調査の方向性

Start by tracing how the visual editor handles document change events while it has focus, and how it distinguishes its own writes from external file changes. The issue names no source files or tests, so locate the editor’s document synchronization entry points and related tests first. Done means external changes appear when there are no pending editor changes, and simultaneous changes prompt the user to choose how to proceed.

索引モデルが issue の本文から書いたものです。

説明

visual-editor

When the visual editor has focus, it does not show any changes that come from outside it. For example, a coding agent, a script, or git checkout can change the file but the visual editor keeps its old content. Then, if you type in the visual editor, its next write puts the old content back over the outside change. The outside change is lost and you see no warning or any indication what happened. If auto-save is on, the change is also lost on disk.

This is probably happening more often now that people use coding agents that edit files while the visual editor is open.

Steps to reproduce

  1. Create test.qmd with a heading and two paragraphs, and save it. To see the change lost on disk, set "files.autoSave": "afterDelay".
  2. Open the file with Quarto: Edit in Visual Mode.
  3. In the integrated terminal, run this command:
    sleep 10 && echo "Line added from outside" >> test.qmd
    
  4. Before the 10 seconds end, click in the body text of the visual editor.
  5. Wait for approximately 5 seconds. The new line does not show in the visual editor. tail -n 1 test.qmd shows that the line is in the file.
  6. Type one character in the visual editor and wait for approximately 3 seconds.
  7. Run tail -n 1 test.qmd again. The new line is not in the file.

If the focus stays in the terminal in step 4, the new line shows in the visual editor after approximately 1 second.

Why this is difficult

The visual editor ignores outside changes while it has focus on purpose. This rule stops its own writes from coming back to it and resetting it while you type. A fix would need to distinguish between outside changes and these writes. A fix also needs to decide what to do when both sides change the file at the same time. If the outside change always wins, you can lose the text that you typed in the last few seconds. If the visual editor always wins, the outside change is lost.

PR #1234 has one approach. In that approach, the outside change always wins.

A possible approach

I think that a better approach would not choose a winner without telling you:

  1. If the visual editor has no changes that it did not write to the document yet, it shows the outside change, also when it has focus. No work would be lost in this case. This case is the usual one for a coding agent, because the agent usually edits the file when you are not typing.
  2. If both sides have changes, the visual editor tells you that the file changed outside it. You then select to load the outside change or to keep your changes in the visual editor, maybe in a diff view of some kind. (The visual editor doesn't provide a diff view right now.)
主要言語
TypeScript
スター
665
フォーク
69
平均マージ
1日 8時間
マージ済み PR(30日)
13

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

quarto-dev/quarto のほかの issue

quarto-dev/quarto の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。