Skip to content

Commit 1ecb513

Browse files
DaniilDemdandmechenko
andauthored
feat(markup): allow to disable search panel (#736)
Co-authored-by: dandmechenko <[email protected]>
1 parent 1618483 commit 1ecb513

File tree

6 files changed

+23
-4
lines changed

6 files changed

+23
-4
lines changed

demo/components/Playground.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export type PlaygroundProps = {
6767
sanitizeHtml?: boolean;
6868
prepareRawMarkup?: boolean;
6969
splitModeOrientation?: 'horizontal' | 'vertical' | false;
70+
searchPanel?: boolean;
7071
stickyToolbar?: boolean;
7172
initialSplitModeEnabled?: boolean;
7273
renderPreviewDefined?: boolean;
@@ -114,6 +115,7 @@ export const Playground = memo<PlaygroundProps>((props) => {
114115
sanitizeHtml,
115116
prepareRawMarkup,
116117
splitModeOrientation,
118+
searchPanel,
117119
stickyToolbar,
118120
renderPreviewDefined,
119121
height,
@@ -237,6 +239,7 @@ export const Playground = memo<PlaygroundProps>((props) => {
237239
parseInsertedUrlAsImage,
238240
renderPreview,
239241
splitMode: splitModeOrientation,
242+
searchPanel,
240243
},
241244
},
242245
[
@@ -245,6 +248,7 @@ export const Playground = memo<PlaygroundProps>((props) => {
245248
linkifyTlds,
246249
breaks,
247250
splitModeOrientation,
251+
searchPanel,
248252
renderPreviewDefined,
249253
renderPreview,
250254
experimental?.needToSetDimensionsForUploadedImages,

demo/components/PlaygroundMini.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type PlaygroundMiniProps = Pick<
1515
| 'sanitizeHtml'
1616
| 'prepareRawMarkup'
1717
| 'splitModeOrientation'
18+
| 'searchPanel'
1819
| 'stickyToolbar'
1920
| 'initialSplitModeEnabled'
2021
| 'renderPreviewDefined'

demo/defaults/args.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const args: Meta<PlaygroundMiniProps>['args'] = {
1212
sanitizeHtml: false,
1313
prepareRawMarkup: false,
1414
splitModeOrientation: 'horizontal',
15+
searchPanel: true,
1516
stickyToolbar: true,
1617
initialSplitModeEnabled: false,
1718
renderPreviewDefined: true,

src/bundle/Editor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ export class EditorImpl extends SafeEventEmitter<EventMapInt> implements EditorI
309309
autocompletion: this.#markupConfig.autocompletion,
310310
directiveSyntax: this.directiveSyntax,
311311
receiver: this,
312+
searchPanel: this.#markupConfig.searchPanel,
312313
}),
313314
);
314315
}

src/bundle/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ export type MarkdownEditorMarkupConfig = {
163163
* The function, used to determine if the pasted text is the image url and should be inserted as an image
164164
*/
165165
parseInsertedUrlAsImage?: ParseInsertedUrlAsImage;
166+
/**
167+
* Show search panel in the editor.
168+
* @default true
169+
*/
170+
searchPanel?: boolean;
166171
};
167172

168173
// do not export this type

src/markup/codemirror/create.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export type CreateCodemirrorParams = {
8888
autocompletion?: Autocompletion;
8989
directiveSyntax: DirectiveSyntaxContext;
9090
preserveEmptyRows: boolean;
91+
searchPanel?: boolean;
9192
};
9293

9394
export function createCodemirror(params: CreateCodemirrorParams) {
@@ -111,6 +112,7 @@ export function createCodemirror(params: CreateCodemirrorParams) {
111112
parseInsertedUrlAsImage,
112113
directiveSyntax,
113114
preserveEmptyRows,
115+
searchPanel = true,
114116
} = params;
115117

116118
const extensions: Extension[] = [gravityTheme, placeholder(placeholderContent)];
@@ -268,12 +270,17 @@ export function createCodemirror(params: CreateCodemirrorParams) {
268270
}
269271
},
270272
}),
271-
SearchPanelPlugin({
272-
anchorSelector: '.g-md-search-anchor',
273-
receiver,
274-
}),
275273
);
276274

275+
if (searchPanel) {
276+
extensions.push(
277+
SearchPanelPlugin({
278+
anchorSelector: '.g-md-search-anchor',
279+
receiver,
280+
}),
281+
);
282+
}
283+
277284
if (preserveEmptyRows) {
278285
extensions.push(
279286
keymap.of([

0 commit comments

Comments
 (0)