From 0e5aa7f116784b374fae18ba950010d531e6b49f Mon Sep 17 00:00:00 2001 From: Chrissi2812 Date: Wed, 29 May 2019 11:25:26 +0200 Subject: [PATCH] add option to disable regex searches --- examples/Components/Routes/Search/index.vue | 4 +++- packages/tiptap-extensions/src/extensions/Search.js | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/Components/Routes/Search/index.vue b/examples/Components/Routes/Search/index.vue index 1a3470d88..4974ad796 100644 --- a/examples/Components/Routes/Search/index.vue +++ b/examples/Components/Routes/Search/index.vue @@ -175,7 +175,9 @@ export default { new HardBreak(), new Heading({ levels: [1, 2, 3] }), new HorizontalRule(), - new Search(), + new Search({ + disableRegex: false, + }), new ListItem(), new OrderedList(), new TodoItem(), diff --git a/packages/tiptap-extensions/src/extensions/Search.js b/packages/tiptap-extensions/src/extensions/Search.js index 95e4fc9cd..624e8484b 100644 --- a/packages/tiptap-extensions/src/extensions/Search.js +++ b/packages/tiptap-extensions/src/extensions/Search.js @@ -24,6 +24,7 @@ export default class Search extends Extension { findClass: 'find', searching: false, caseSensitive: false, + disableRegex: true, } } @@ -103,7 +104,7 @@ export default class Search extends Extension { find(searchTerm) { return ({ tr }, dispatch) => { this.options.searching = true - this.searchTerm = searchTerm + this.searchTerm = (this.options.disableRegex) ? searchTerm.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') : searchTerm dispatch(tr) }