donteatfriedrice
2024-07-16 06:15:39 +00:00
parent b15294d80c
commit 53eb4aca8d
5 changed files with 51 additions and 13 deletions

View File

@@ -26,6 +26,7 @@ const CommonActions = [
{
icon: ReplaceIcon,
title: 'Replace selection',
toast: 'Successfully replaced',
handler: async (
host: EditorHost,
content: string,
@@ -39,7 +40,7 @@ const CommonActions = [
currentBlockSelections,
})
.run();
if (!data.selectedBlocks) return;
if (!data.selectedBlocks) return false;
reportResponse('result:replace');
@@ -52,7 +53,7 @@ const CommonActions = [
currentTextSelection.from.length,
content
);
return;
return true;
}
}
@@ -63,11 +64,13 @@ const CommonActions = [
data.selectedBlocks.map(block => block.model),
currentTextSelection
);
return true;
},
},
{
icon: InsertBelowIcon,
title: 'Insert below',
toast: 'Successfully inserted',
handler: async (
host: EditorHost,
content: string,
@@ -83,13 +86,14 @@ const CommonActions = [
currentImageSelections,
})
.run();
if (!data.selectedBlocks) return;
if (!data.selectedBlocks) return false;
reportResponse('result:insert');
await insertBelow(
host,
content,
data.selectedBlocks[data.selectedBlocks?.length - 1]
);
return true;
},
},
];
@@ -99,6 +103,7 @@ export const PageEditorActions = [
{
icon: CreateIcon,
title: 'Create as a doc',
toast: 'New doc created',
handler: (host: EditorHost, content: string) => {
reportResponse('result:add-page');
const newDoc = host.doc.collection.createDoc();
@@ -122,6 +127,8 @@ export const PageEditorActions = [
complete = true;
insertFromMarkdown(newHost, content, noteId, 0).catch(console.error);
})();
return true;
},
},
];
@@ -131,6 +138,7 @@ export const EdgelessEditorActions = [
{
icon: CreateIcon,
title: 'Add to edgeless as note',
toast: 'New note created',
handler: async (host: EditorHost, content: string) => {
reportResponse('result:add-note');
const { doc } = host;
@@ -157,6 +165,8 @@ export const EdgelessEditorActions = [
elements: [id],
editing: false,
});
return true;
},
},
];

View File

@@ -110,6 +110,16 @@ export class ChatCopyMore extends WithDisposable(LitElement) {
this._morePopper?.toggle();
}
private readonly _notifySuccess = (title: string) => {
const rootService = this.host.spec.getService('affine:page');
const { notificationService } = rootService;
notificationService?.notify({
title: title,
accent: 'success',
onClose: function (): void {},
});
};
private async _retry() {
const { doc } = this.host;
try {
@@ -180,7 +190,14 @@ export class ChatCopyMore extends WithDisposable(LitElement) {
</style>
<div class="copy-more">
${content
? html`<div @click=${() => copyText(host, content)}>
? html`<div
@click=${async () => {
const success = await copyText(host, content);
if (success) {
this._notifySuccess('Copied to clipboard');
}
}}
>
${CopyIcon}
<affine-tooltip>Copy</affine-tooltip>
</div>`
@@ -205,13 +222,18 @@ export class ChatCopyMore extends WithDisposable(LitElement) {
action => action.title,
action => {
return html`<div
@click=${() =>
action.handler(
@click=${async () => {
const success = await action.handler(
host,
content,
this.curTextSelection,
this.curBlockSelections
)}
);
if (success) {
this._notifySuccess(action.toast);
}
}}
>
${action.icon}
<div>${action.title}</div>

View File

@@ -545,13 +545,22 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
return;
}
await action.handler(
const success = await action.handler(
host,
content,
this._currentTextSelection,
this._currentBlockSelections,
this._currentImageSelections
);
const rootService = host.spec.getService('affine:page');
const { notificationService } = rootService;
if (success) {
notificationService?.notify({
title: action.toast,
accent: 'success',
onClose: function (): void {},
});
}
}}
>
${action.title}

View File

@@ -28,7 +28,8 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
.chat-panel-container {
display: flex;
flex-direction: column;
padding: 0 12px;
padding: 0 16px;
padding-top: 8px;
height: 100%;
}

View File

@@ -140,9 +140,5 @@ export const copyText = async (host: EditorHost, text: string) => {
.flatMap(model => model.children);
const slice = Slice.fromModels(previewDoc, models);
await host.std.clipboard.copySlice(slice);
const { notificationService } = host.std.spec.getService('affine:page');
if (notificationService) {
notificationService.toast('Copied to clipboard');
}
return true;
};