Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change the time to register "create" event. support insert multi imgs at once. #24

Merged
merged 15 commits into from
Oct 23, 2023

Conversation

dotkt
Copy link
Contributor

@dotkt dotkt commented Oct 15, 2023

change the time to register "create" event. support insert multi imgs at once.

@xRyul
Copy link
Owner

xRyul commented Oct 18, 2023

Hey, thanks for contributing.

  • How do you compile it? ESlint throws quite a few errors.
  • Please remove any variables, or console logs which are not being used.

Following seems to allow multi drop and even saves a few ms during load. Many thanks 🙏 although, going to have to test it further, especially with various SYNC methods

		this.dropListener = () => {
			userAction = true;
			setTimeout(() => userAction = false, 10000);
		};

		this.app.workspace.onLayoutReady(() => {
			document.addEventListener("paste", this.pasteListener);
			document.addEventListener('drop', this.dropListener);
			this.registerEvent(
				this.app.vault.on('create', (file: TFile) => {
					if (!(file instanceof TFile)) return;
					if (isImage(file) && userAction) {
						this.renameFile1(file);
					}
					// userAction = false; // uncommented to allow multi-drop
				})
			);
		})
		
		...
		
		const currentLine = cursor.line;
		function escapeRegExp(string: string) {
			return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& 表示整个匹配的字符串
		}
		const findText = escapeRegExp(linkText);
		const replaceText = newLinkText;
		const docContent = editor.getValue();
		const regex = new RegExp(findText, 'g');
		const newContent = docContent.replace(regex, replaceText);
		editor.setValue(newContent);
		editor.setCursor({ line: currentLine, ch: 0 });
		// Ensure the current line is in a visible position
		editor.scrollIntoView({ from: { line: currentLine, ch: 0 }, to: { line: currentLine, ch: 0 } });
		

@dotkt
Copy link
Contributor Author

dotkt commented Oct 20, 2023 via email

@xRyul xRyul merged commit ca23756 into xRyul:master Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants