fix: draft not move to sub

This commit is contained in:
lin onetwo 2025-10-29 16:09:03 +08:00
parent c7b5c0e806
commit f35d2e8c33
5 changed files with 66 additions and 33 deletions

View file

@ -93,6 +93,25 @@ Solution:
node_modules/.bin/electron-rebuild -f -w better-sqlite3
```
## Error: The module '/Users/linonetwo/Desktop/repo/TidGi-Desktop/node_modules/opencv4nodejs-prebuilt/build/Release/opencv4nodejs.node'
```log
was compiled against a different Node.js version using
NODE_MODULE_VERSION 127. This version of Node.js requires
NODE_MODULE_VERSION 135. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
```
(The number above is smaller)
Don't use `npm rebuild` or `npm install`, it doesn't works, it will still build for nodejs. We need to build with electron:
```sh
./node_modules/.bin/electron-rebuild
```
See <https://github.com/justadudewhohacks/opencv4nodejs/issues/401#issuecomment-463434713> if you still have problem rebuild opencv for @nut-tree/nut-js
## During test, The module 'node_modules\better-sqlite3\build\Release\better_sqlite3.node' was compiled against a different Node.js version using
```log
@ -113,25 +132,6 @@ cross-env ELECTRON_RUN_AS_NODE=true ./node_modules/.bin/electron ./node_modules/
救急可以用 `chcp 65001 && pnpm run test:unit`如果有空重启电脑则在时区设置里找到「系统区域设置」里勾选「Unicode Beta版」重启即可。
## Error: The module '/Users/linonetwo/Desktop/repo/TidGi-Desktop/node_modules/opencv4nodejs-prebuilt/build/Release/opencv4nodejs.node'
```log
was compiled against a different Node.js version using
NODE_MODULE_VERSION 127. This version of Node.js requires
NODE_MODULE_VERSION 135. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
```
(The number above is smaller)
Don't use `npm rebuild` or `npm install`, it doesn't works, it will still build for nodejs. We need to build with electron:
```sh
./node_modules/.bin/electron-rebuild
```
See <https://github.com/justadudewhohacks/opencv4nodejs/issues/401#issuecomment-463434713> if you still have problem rebuild opencv for @nut-tree/nut-js
## Command failed with exit code 1
When you see an error like:

View file

@ -31,28 +31,45 @@ Feature: Filesystem Plugin
And I wait for SSE and watch-fs to be ready
# Click on SubWiki workspace icon to open the TestTag tiddler
When I click on a "SubWiki workspace button" element with selector "div[data-testid^='workspace-']:has-text('SubWiki')"
And I wait for 0.5 seconds
And I wait for 0.2 seconds
# Subwiki tiddler should now be visible
And I should see "TestTag" in the browser view content
# create tiddler with tag
And I click on "add tiddler button" element in browser view with selector "button[aria-label='']"
And I wait for 0.2 seconds
And I type "Test Tiddler Title" in "title input" element in browser view with selector "input.tc-titlebar.tc-edit-texteditor"
And I type "TestTag" in "tag input" element in browser view with selector "input.tc-edit-texteditor.tc-popup-handle"
And I press "Enter" in browser view
And I click on "confirm button" element in browser view with selector "button[aria-label='']"
# Verify the tiddler file exists in sub-wiki folder (not in tiddlers subfolder)
Then file "Test Tiddler Title.tid" should exist in "{tmpDir}/SubWiki"
# Focus on title input, clear it, and type new title in the draft tiddler
And I click on "title input" element in browser view with selector "div[data-tiddler-title^='Draft of'] input.tc-titlebar.tc-edit-texteditor"
And I press "Control+a" in browser view
And I press "Delete" in browser view
And I type "TestTiddlerTitle" in "title input" element in browser view with selector "div[data-tiddler-title^='Draft of'] input.tc-titlebar.tc-edit-texteditor"
# Input tag by typing in the tag input field
And I click on "tag input" element in browser view with selector "div[data-tiddler-title^='Draft of'] input.tc-edit-texteditor.tc-popup-handle"
And I wait for 0.1 seconds
And I type "TestTag" in "tag input" element in browser view with selector "div[data-tiddler-title^='Draft of'] input.tc-edit-texteditor.tc-popup-handle"
# Click the add tag button to confirm the tag (not just typing)
And I click on "add tag button" element in browser view with selector "div[data-tiddler-title^='Draft of'] span.tc-add-tag-button button"
# Wait more time for ipc and filesystem to process
And I wait for 3 seconds
# Verify the DRAFT tiddler has been routed to sub-wiki immediately after adding the tag
# The draft file should now be in SubWiki folder with the tag applied
Then file "Draft of ''.tid" should exist in "{tmpDir}/SubWiki"
# Click confirm button to save the tiddler
And I click on "confirm button" element in browser view with selector "div[data-tiddler-title^='Draft of'] button[aria-label='']"
And I wait for 1 seconds
# Verify the final tiddler file exists in sub-wiki folder after save
# After confirming the draft, it should be saved as TestTiddlerTitle.tid in SubWiki
Then file "TestTiddlerTitle.tid" should exist in "{tmpDir}/SubWiki"
# Test SSE is still working after SubWiki creation - modify a main wiki tiddler
When I modify file "{tmpDir}/wiki/tiddlers/Index.tid" to contain "Main wiki content modified after SubWiki creation"
Then I wait for tiddler "Index" to be updated by watch-fs
# Verify main wiki modification appears (Index is always open by default, no need to click)
And I wait for 2 seconds
Then I should see "Main wiki content modified after SubWiki creation" in the browser view content
# Test modification in sub-workspace via symlink
# Modify the tiddler file externally - need to preserve .tid format with metadata
When I modify file "{tmpDir}/SubWiki/Test Tiddler Title.tid" to contain "Content modified in SubWiki symlink"
When I modify file "{tmpDir}/SubWiki/TestTiddlerTitle.tid" to contain "Content modified in SubWiki symlink"
# Wait for watch-fs to detect the change
Then I wait for tiddler "Test Tiddler Title" to be updated by watch-fs
Then I wait for tiddler "TestTiddlerTitle" to be updated by watch-fs
And I wait for 2 seconds
# Verify the modified content appears in the wiki
Then I should see "Content modified in SubWiki symlink" in the browser view content
@ -93,6 +110,7 @@ Feature: Filesystem Plugin
And I click on "sidebar tab" element in browser view with selector "div.tc-tab-buttons.tc-sidebar-tabs-main > button:has-text('')"
And I wait for 0.5 seconds
And I click on "timeline link" element in browser view with selector "div.tc-timeline a.tc-tiddlylink:has-text('TestTiddler')"
And I wait for 0.5 seconds
Then I should see "Original content" in the browser view content
# Modify the file externally
When I modify file "{tmpDir}/wiki/tiddlers/TestTiddler.tid" to contain "Modified content from external editor"
@ -148,7 +166,7 @@ Feature: Filesystem Plugin
Then I wait for tiddler "NewName" to be updated by watch-fs
# Navigate to timeline to verify changes
And I click on "sidebar tab" element in browser view with selector "div.tc-tab-buttons.tc-sidebar-tabs-main > button:has-text('')"
And I wait for 0.5 seconds
And I wait for 1 seconds
# Verify new name appears
And I click on "timeline link" element in browser view with selector "div.tc-timeline a.tc-tiddlylink:has-text('NewName')"
Then I should see "Content before rename" in the browser view content

View file

@ -20,6 +20,7 @@
"test:unit:coverage": "pnpm run test:unit --coverage",
"test:prepare-e2e": "cross-env READ_DOC_BEFORE_USING='docs/Testing.md' && pnpm run clean && pnpm run build:plugin && cross-env NODE_ENV=test DEBUG=electron-forge:* electron-forge package",
"test:e2e": "rimraf -- ./userData-test ./wiki-test && cross-env NODE_ENV=test tsx scripts/developmentMkdir.ts && cross-env NODE_ENV=test cucumber-js --config features/cucumber.config.js",
"test:manual-e2e": "pnpm exec cross-env NODE_ENV=test tsx ./scripts/start-e2e-app.ts",
"make": "pnpm run build:plugin && cross-env NODE_ENV=production electron-forge make",
"make:analyze": "cross-env ANALYZE=true pnpm run make",
"init:git-submodule": "git submodule update --init --recursive && git submodule update --remote",

View file

@ -117,6 +117,7 @@ export class FileSystemAdaptor {
/**
* Main routing logic: determine where a tiddler should be saved based on its tags.
* For draft tiddlers, check the original tiddler's tags.
*/
async getTiddlerFileInfo(tiddler: Tiddler): Promise<FileInfo | null> {
if (!this.boot.wikiTiddlersPath) {
@ -124,10 +125,23 @@ export class FileSystemAdaptor {
}
const title = tiddler.fields.title;
const tags = tiddler.fields.tags ?? [];
let tags = tiddler.fields.tags ?? [];
const fileInfo = this.boot.files[title];
try {
// For draft tiddlers (draft.of field), also check the original tiddler's tags
// This ensures drafts are saved to the same sub-wiki as their target tiddler
const draftOf = tiddler.fields['draft.of'];
if (draftOf && typeof draftOf === 'string' && $tw.wiki) {
// Get the original tiddler from the wiki
const originalTiddler = $tw.wiki.getTiddler(draftOf);
if (originalTiddler) {
const originalTags = originalTiddler.fields.tags ?? [];
// Merge tags from the original tiddler with the draft's tags
tags = [...new Set([...tags, ...originalTags])];
}
}
let matchingSubWiki: IWikiWorkspace | undefined;
for (const tag of tags) {
matchingSubWiki = this.tagNameToSubWiki.get(tag);

View file

@ -478,7 +478,7 @@ export class WatchFileSystemAdaptor extends FileSystemAdaptor {
// not wrapped in a .fields property
const tiddlerTitle = tiddler?.title;
if (!tiddlerTitle) {
this.logger.alert(`[WATCH_FS_ERROR] Tiddler has no title`);
this.logger.alert(`[WATCH_FS_ERROR] Tiddler has no title. Tiddler object: ${JSON.stringify(tiddler)}`);
continue;
}