Skip to content

Commit

Permalink
feat: provide find and replace functionality for the default rich tex…
Browse files Browse the repository at this point in the history
…t editor (#5206)

#### What type of PR is this?

/kind feature

#### What this PR does / why we need it:

为默认富文本编辑器添加查找与搜索的功能扩展。

快捷键:

当焦点处于编辑器中时,可以使用 `Mod+f` 来唤起查找与搜索框,或者点击顶部工具栏来打开。
当焦点处于查找与搜索框时,按下 `Ecs` 可进行关闭。

<img width="1920" alt="image" src="https://github.com/halo-dev/halo/assets/31335418/03a54bb8-2cc4-4cb0-9a18-fd0e9aede564">

#### How to test it?

测试查找与搜索功能是否正常

#### Which issue(s) this PR fixes:

Fixes #5195 

#### Does this PR introduce a user-facing change?
```release-note
为默认富文本编辑器添加查找与搜索的功能扩展。
```
  • Loading branch information
LIlGG authored Jan 24, 2024
1 parent ddbc73b commit 3846525
Show file tree
Hide file tree
Showing 13 changed files with 1,133 additions and 3 deletions.
9 changes: 6 additions & 3 deletions console/packages/editor/src/components/EditorHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function getToolboxItemsFromExtensions() {
>
<div class="inline-flex items-center justify-center">
<VMenu>
<button class="p-1 rounded-sm hover:bg-gray-100">
<button class="p-1 rounded-sm hover:bg-gray-100" tabindex="-1">
<MdiPlusCircle class="text-[#4CCBA0]" />
</button>
<template #popper>
Expand All @@ -75,6 +75,7 @@ function getToolboxItemsFromExtensions() {
v-for="(toolboxItem, index) in getToolboxItemsFromExtensions()"
v-bind="toolboxItem.props"
:key="index"
tabindex="-1"
/>
</div>
</template>
Expand All @@ -90,9 +91,10 @@ function getToolboxItemsFromExtensions() {
:is="item.component"
v-if="!item.children?.length"
v-bind="item.props"
tabindex="-1"
/>
<VMenu v-else class="inline-flex">
<component :is="item.component" v-bind="item.props" />
<VMenu v-else class="inline-flex" tabindex="-1">
<component :is="item.component" v-bind="item.props" tabindex="-1" />
<template #popper>
<div
class="relative rounded-md bg-white overflow-hidden drop-shadow w-48 p-1 max-h-72 overflow-y-auto"
Expand All @@ -102,6 +104,7 @@ function getToolboxItemsFromExtensions() {
:is="child.component"
v-for="(child, childIndex) in item.children"
:key="childIndex"
tabindex="-1"
/>
</div>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ withDefaults(
]"
class="p-1 rounded-sm"
:disabled="disabled"
tabindex="-1"
@click="action"
>
<component :is="icon" />
Expand Down
2 changes: 2 additions & 0 deletions console/packages/editor/src/dev/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
ExtensionNodeSelected,
ExtensionTrailingNode,
ExtensionListKeymap,
ExtensionSearchAndReplace,
} from "../index";
const content = useLocalStorage("content", "");
Expand Down Expand Up @@ -109,6 +110,7 @@ const editor = useEditor({
ExtensionNodeSelected,
ExtensionTrailingNode,
ExtensionListKeymap,
ExtensionSearchAndReplace,
],
onUpdate: () => {
content.value = editor.value?.getHTML() + "";
Expand Down
3 changes: 3 additions & 0 deletions console/packages/editor/src/extensions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import ExtensionText from "./text";
import ExtensionDraggable from "./draggable";
import ExtensionNodeSelected from "./node-selected";
import ExtensionTrailingNode from "./trailing-node";
import ExtensionSearchAndReplace from "./search-and-replace";

const allExtensions = [
ExtensionBlockquote,
Expand Down Expand Up @@ -98,6 +99,7 @@ const allExtensions = [
ExtensionColumn,
ExtensionNodeSelected,
ExtensionTrailingNode,
ExtensionSearchAndReplace,
];

export {
Expand Down Expand Up @@ -144,4 +146,5 @@ export {
ExtensionNodeSelected,
ExtensionTrailingNode,
ExtensionListKeymap,
ExtensionSearchAndReplace,
};
Loading

0 comments on commit 3846525

Please sign in to comment.