Skip to content

Commit

Permalink
feat: support undoedit
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Oct 26, 2024
1 parent b10c49f commit 1d9d55a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"publisher": "oeyoews",
"name": "usewiki2",
"displayName": "usewiki2",
"version": "1.9.0",
"version": "2.0.0",
"private": true,
"packageManager": "[email protected]",
"description": "",
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ function App() {
});
messenger.send('placeholder');
messenger.on('placeholder', ({ text }) => setPlaceholder(text));
messenger.on('edit', ({ text }) => {
setInputValue(text);
inputRef.current?.focus();
});
}, []);

return (
Expand Down
2 changes: 2 additions & 0 deletions src/commands/usewikiCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import sendTiddler from '../sendTiddler';
import { notify } from '../notify';

export const name = 'usewiki2.tiddlywiki';

/** @deprecated */
export async function cli() {
const text = await vscode.window.showInputBox({
title: '书写太微之书',
Expand Down
2 changes: 1 addition & 1 deletion src/generated/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Meta info
export const publisher = "oeyoews"
export const name = "usewiki2"
export const version = "1.9.0"
export const version = "2.0.0"
export const displayName = "usewiki2"
export const description = undefined
export const extensionId = `${publisher}.${name}`
Expand Down
17 changes: 12 additions & 5 deletions src/sendTiddler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { notify } from './notify';
import { defaultTag, getPort, getIp, defaultUsername, getType } from './config';
export default async function sendTiddler(text: string) {
import { type WebviewMessenger } from './utils/extensionMessenger';
const UNDO = '撤回';
const UNDOEDIT = '撤回并编辑';
export default async function sendTiddler(
text: string,
messenger: WebviewMessenger
) {
const port = getPort();
const ip = getIp();

Expand Down Expand Up @@ -49,11 +55,12 @@ export default async function sendTiddler(text: string) {
});

if (response.status === 204) {
notify(`发送成功(${title})`, 'info', ['撤销']).then((data) => {
if (data === '撤销') {
notify(`发送成功(${title})`, 'info', [UNDO, UNDOEDIT]).then((data) => {
if (data === UNDO) {
undoSendTiddler();
} else if (data === '撤回并重新编辑') {
// postmessage
} else if (data === UNDOEDIT) {
undoSendTiddler();
messenger.send('edit', { text });
}
});
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/webviews/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class usewikiViewProvider implements vscode.WebviewViewProvider {
openWikiCmd.cli();
});
messenger.on('sendWiki', ({ text }) => {
sendTiddler(text).then(() => {
sendTiddler(text, messenger).then(() => {
if (enableSendSound()) {
messenger.send('playSound');
}
Expand Down

0 comments on commit 1d9d55a

Please sign in to comment.