diff --git a/index.html b/index.html
index d18fe3d..4cf2e17 100644
--- a/index.html
+++ b/index.html
@@ -623,25 +623,8 @@ chmod 755 kbtd`;
// --- File Operations ---
- async function writeFile(text) {
- try {
- const writable = await state.fileHandle.createWritable();
- await writable.write(text);
- await writable.close();
- console.log('File written successfully');
-
- const file = await state.fileHandle.getFile();
- state.lastModified = file.lastModified;
-
- reloadFromText(text);
- } catch (err) {
- console.error('Error writing file:', err);
- alert('Error saving file.');
- }
- }
-
function reloadFromText(text) {
- console.log('Reloading from text after write');
+ console.log('Reloading from text');
state.sections = parseMarkdown(text);
console.log('Parsed sections:', state.sections);
@@ -652,6 +635,24 @@ chmod 755 kbtd`;
}
}
+ async function writeFile(text) {
+ try {
+ console.log('Writing file and updating UI');
+ reloadFromText(text);
+
+ const writable = await state.fileHandle.createWritable();
+ await writable.write(text);
+ await writable.close();
+ console.log('File written successfully');
+
+ const file = await state.fileHandle.getFile();
+ state.lastModified = file.lastModified;
+ } catch (err) {
+ console.error('Error writing file:', err);
+ alert('Error saving file.');
+ }
+ }
+
async function updateLineInFile(lineNum, newText) {
console.log('updateLineInFile:', lineNum, newText);
const file = await state.fileHandle.getFile();