commit 8d10889aeb7c9d1727a4980668da3054e1ea5b98
parent 3203d3eb08b0c1feff462509b8892bde8d6b3be0
Author: unitehenry <unitehenry@gmail.com>
Date: Thu, 24 Oct 2019 14:10:01 -0400
ctrl + enter demo
Diffstat:
3 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/demo/src/App.vue b/demo/src/App.vue
@@ -12,9 +12,11 @@
style="min-height:300px; width: 800px;"
meta-url="metaUrl"
:custom-toolbar-button="customButton"
- :submit-on-enter="submitOnEnter"
+ :on-enter="submitOnEnter"
></striven-editor>
<div class="custom-button" ref="customButton" @click="sendContent">Send</div>
+ <br />
+ <i>ctrl + enter to submit</i>
</div>
</template>
@@ -38,11 +40,17 @@ export default {
alert("invalid file");
},
placeholder: "Begin typing in this editor...",
- submitOnEnter: ({ content, files }) => {
- if (content || files.length) {
- console.log({ content, files });
+ submitOnEnter: (e) => {
+ if(e.keyCode === 13 && e.ctrlKey) {
+ const content = this.editor.getContent();
+ const files = this.editor.getFiles();
+
+ if(content || files.length) {
+ console.log({ content, files });
+ this.editor.clearContent();
+ this.editor.clearFiles();
+ }
}
- this.editor.body.blur();
},
customButton: () => this.$refs.customButton,
editor: null
diff --git a/src/striveneditor.js b/src/striveneditor.js
@@ -575,28 +575,20 @@ export default class StrivenEditor {
this.range = this.getRange();
- if (this.options.submitOnEnter && e.keyCode === 13 && !e.shiftKey) {
+ if (this.options.onEnter && e.keyCode === 13) {
if (!document.queryCommandState('insertOrderedList') && !document.queryCommandState('insertUnorderedList')) {
- const hasText = !!this.getTextContent();
- const hasImage = !!body.querySelector('img');
-
- // remove break from enter
- if (hasText || hasImage) {
- const breaks = body.querySelectorAll('div');
- const divBreak = breaks[breaks.length ? breaks.length - 1 : 0];
- divBreak && divBreak.remove();
- }
-
- const content = this.getContent();
- const files = this.getFiles();
+ // const hasText = !!this.getTextContent();
+ // const hasImage = !!body.querySelector('img');
- this.clearContent();
- this.filesSection && this.clearFiles();
+ // // remove break from enter
+ // if (hasText || hasImage) {
+ // const breaks = body.querySelectorAll('div');
+ // const divBreak = breaks[breaks.length ? breaks.length - 1 : 0];
+ // divBreak && divBreak.remove();
+ // }
- if (files.length || hasText || hasImage) {
- this.options.submitOnEnter({ content: (hasText || hasImage) && content, files });
- }
+ this.options.onEnter(e);
}
}
diff --git a/src/vue-striveneditor.vue b/src/vue-striveneditor.vue
@@ -20,7 +20,7 @@ export default {
imageUrl: String,
customToolbarOption: Object,
activeOptionColor: String,
- submitOnEnter: Function,
+ onEnter: Function,
value: String,
customToolbarButton: Function
},