fix: 修复打开/切换文件后误标记为已修改的问题
This commit is contained in:
@@ -63,6 +63,7 @@
|
|||||||
let viewMode = 'split';
|
let viewMode = 'split';
|
||||||
let updateTimer = null;
|
let updateTimer = null;
|
||||||
let lineCountCache = 0;
|
let lineCountCache = 0;
|
||||||
|
let _loadingTab = false; // 加载 tab 内容期间跳过 input 事件的 isModified 标记
|
||||||
let currentRootPath = null;
|
let currentRootPath = null;
|
||||||
|
|
||||||
// Search state
|
// Search state
|
||||||
@@ -674,6 +675,7 @@
|
|||||||
function loadTabState(tab) {
|
function loadTabState(tab) {
|
||||||
// 使用 execCommand('insertText') 替换内容,保留 undo/redo 历史
|
// 使用 execCommand('insertText') 替换内容,保留 undo/redo 历史
|
||||||
// setRangeText 会清空 undo 栈,所以此处必须用 execCommand
|
// setRangeText 会清空 undo 栈,所以此处必须用 execCommand
|
||||||
|
_loadingTab = true;
|
||||||
editor.focus();
|
editor.focus();
|
||||||
editor.select();
|
editor.select();
|
||||||
const inserted = document.execCommand('insertText', false, tab.content);
|
const inserted = document.execCommand('insertText', false, tab.content);
|
||||||
@@ -699,6 +701,7 @@
|
|||||||
|
|
||||||
// Update modified state
|
// Update modified state
|
||||||
setModified(tab.isModified);
|
setModified(tab.isModified);
|
||||||
|
_loadingTab = false;
|
||||||
|
|
||||||
// Notify main process about active file
|
// Notify main process about active file
|
||||||
if (typeof window.electronAPI !== 'undefined') {
|
if (typeof window.electronAPI !== 'undefined') {
|
||||||
@@ -1101,9 +1104,12 @@
|
|||||||
if (!tab || !tab.filePath) return;
|
if (!tab || !tab.filePath) return;
|
||||||
const result = await window.electronAPI.reloadFile();
|
const result = await window.electronAPI.reloadFile();
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
_loadingTab = true;
|
||||||
editor.value = result.content;
|
editor.value = result.content;
|
||||||
|
_loadingTab = false;
|
||||||
tab.content = result.content;
|
tab.content = result.content;
|
||||||
tab.isModified = false;
|
tab.isModified = false;
|
||||||
|
setModified(false);
|
||||||
lineCountCache = 0;
|
lineCountCache = 0;
|
||||||
updateLineNumbers();
|
updateLineNumbers();
|
||||||
renderMarkdown(result.content);
|
renderMarkdown(result.content);
|
||||||
@@ -1149,6 +1155,7 @@
|
|||||||
// ===== Event Listeners =====
|
// ===== Event Listeners =====
|
||||||
function initEventListeners() {
|
function initEventListeners() {
|
||||||
editor.addEventListener('input', () => {
|
editor.addEventListener('input', () => {
|
||||||
|
if (_loadingTab) { scheduleUpdate(); return; } // 加载中不标记修改
|
||||||
const tab = getActiveTab();
|
const tab = getActiveTab();
|
||||||
if (tab) {
|
if (tab) {
|
||||||
tab.isModified = true;
|
tab.isModified = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user