remove toggleSearch command

This commit is contained in:
Philipp Kühn 2019-06-04 22:20:27 +02:00
parent 17c1e8cf46
commit d759eb4d9d
3 changed files with 50 additions and 75 deletions

View File

@ -105,34 +105,25 @@
<icon name="redo" /> <icon name="redo" />
</button> </button>
<span <div class="search">
class="menubar__button"
@click="editor.commands.toggleSearch"
>
Search
<div
class="search-modal"
@click.stop
v-if="editor.extensions.options.search.searching"
>
<input <input
ref="search" ref="search"
@keydown.enter.prevent="editor.commands.find(searchTerm)" @keydown.enter.prevent="editor.commands.find(searchTerm)"
placeholder="Search..." placeholder="Search …"
type="text" type="text"
v-model="searchTerm" v-model="searchTerm"
><input />
<input
@keydown.enter.prevent="editor.commands.replace(replaceWith)" @keydown.enter.prevent="editor.commands.replace(replaceWith)"
placeholder="Replace..." placeholder="Replace …"
type="text" type="text"
v-model="replaceWith" v-model="replaceWith"
> />
<button @click="editor.commands.find(searchTerm)">Find</button> <button class="button" @click="editor.commands.find(searchTerm)">Find</button>
<button @click="editor.commands.clearSearch()">Clear</button> <button class="button" @click="editor.commands.clearSearch()">Clear</button>
<button @click="editor.commands.replace(replaceWith)">Replace</button> <button class="button" @click="editor.commands.replace(replaceWith)">Replace</button>
<button @click="editor.commands.replaceAll(replaceWith)">Replace All</button> <button class="button" @click="editor.commands.replaceAll(replaceWith)">Replace All</button>
</div> </div>
</span>
</div> </div>
</editor-menu-bar> </editor-menu-bar>
@ -173,7 +164,7 @@ export default {
}, },
data() { data() {
return { return {
searching: false, // searching: false,
searchTerm: null, searchTerm: null,
replaceWith: null, replaceWith: null,
editor: new Editor({ editor: new Editor({
@ -199,16 +190,6 @@ export default {
new Underline(), new Underline(),
new History(), new History(),
], ],
onUpdate: ({ getJSON }) => {
this.json = getJSON()
},
onToggleSearch: searching => {
this.$nextTick(() => {
if (searching) {
this.$refs.search.focus()
}
})
},
content: ` content: `
<h2> <h2>
Hi there, Hi there,
@ -240,25 +221,34 @@ export default {
} }
</script> </script>
<style> <style lang="scss">
.menubar__button { @import "~variables";
position: relative;
}
.search-modal { .search {
position: absolute;
top: 100%;
display: flex; display: flex;
background: #fff; flex-wrap: wrap;
padding: .5em; background-color: rgba($color-black, 0.1);
box-shadow: 0 2px 4px #0003; padding: 0.5rem;
border-radius: 2px; border-radius: 5px;
left: 0; margin-top: 1rem;
margin-top: 0.25em;
border: solid 2px; input {
padding: 0.25rem;
border: 0;
border-radius: 3px;
margin-right: 0.2rem;
font: inherit;
font-size: 0.8rem;
width: 20%;
flex: 1;
} }
.find { button {
background: rgba(255, 213, 0, 0.5);
} }
}
.find {
background: rgba(255, 213, 0, 0.5);
}
</style> </style>

View File

@ -72,6 +72,10 @@ h3 {
border-radius: 3px; border-radius: 3px;
cursor: pointer; cursor: pointer;
background-color: rgba($color-black, 0.1); background-color: rgba($color-black, 0.1);
&:hover {
background-color: rgba($color-black, 0.15);
}
} }
.message { .message {

View File

@ -15,10 +15,6 @@ export default class Search extends Extension {
return 'search' return 'search'
} }
init() {
this.editor.events.push('toggleSearch')
}
get defaultOptions() { get defaultOptions() {
return { return {
autoSelectNext: true, autoSelectNext: true,
@ -30,27 +26,12 @@ export default class Search extends Extension {
} }
} }
toggleSearch() {
return () => {
this.options.searching = !this.options.searching
this.editor.emit('toggleSearch', this.options.searching)
return true
}
}
keys() {
return {
'Mod-f': this.toggleSearch(),
}
}
commands() { commands() {
return { return {
find: attrs => this.find(attrs), find: attrs => this.find(attrs),
replace: attrs => this.replace(attrs), replace: attrs => this.replace(attrs),
replaceAll: attrs => this.replaceAll(attrs), replaceAll: attrs => this.replaceAll(attrs),
clearSearch: () => this.clear(), clearSearch: () => this.clear(),
toggleSearch: () => this.toggleSearch(),
} }
} }