Fixed new comment cancel to keep discussion gutter open
This commit is contained in:
parent
794cd94db6
commit
5c7e0ae662
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="comment comment--new" @keyup.esc="setIsCommenting(false)">
|
<div class="comment comment--new" @keyup.esc="cancelNewComment">
|
||||||
<div class="comment__header flex flex--row flex--space-between flex--align-center">
|
<div class="comment__header flex flex--row flex--space-between flex--align-center">
|
||||||
<div class="comment__user flex flex--row flex--align-center">
|
<div class="comment__user flex flex--row flex--align-center">
|
||||||
<div class="comment__user-image">
|
<div class="comment__user-image">
|
||||||
@ -14,14 +14,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="comment__buttons flex flex--row flex--end">
|
<div class="comment__buttons flex flex--row flex--end">
|
||||||
<button class="comment__button button" @click="setIsCommenting(false)">Cancel</button>
|
<button class="comment__button button" @click="cancelNewComment">Cancel</button>
|
||||||
<button class="comment__button button" @click="addComment">Ok</button>
|
<button class="comment__button button" @click="addComment">Ok</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapGetters, mapMutations } from 'vuex';
|
import { mapGetters, mapMutations, mapActions } from 'vuex';
|
||||||
import Prism from 'prismjs';
|
import Prism from 'prismjs';
|
||||||
import UserImage from '../UserImage';
|
import UserImage from '../UserImage';
|
||||||
import cledit from '../../libs/cledit';
|
import cledit from '../../libs/cledit';
|
||||||
@ -38,9 +38,11 @@ export default {
|
|||||||
]),
|
]),
|
||||||
methods: {
|
methods: {
|
||||||
...mapMutations('discussion', [
|
...mapMutations('discussion', [
|
||||||
'setIsCommenting',
|
|
||||||
'setNewCommentFocus',
|
'setNewCommentFocus',
|
||||||
]),
|
]),
|
||||||
|
...mapActions('discussion', [
|
||||||
|
'cancelNewComment',
|
||||||
|
]),
|
||||||
addComment() {
|
addComment() {
|
||||||
const text = this.$store.state.discussion.newCommentText.trim();
|
const text = this.$store.state.discussion.newCommentText.trim();
|
||||||
if (text.length) {
|
if (text.length) {
|
||||||
|
@ -64,14 +64,13 @@ function stripDiscussionOffsets(objectMap) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function restoreDiscussionOffsets(content, markerKeys) {
|
function restoreDiscussionOffsets(content, markerKeys) {
|
||||||
|
if (markerKeys.length) {
|
||||||
// Go through markers
|
// Go through markers
|
||||||
let count = 0;
|
let count = 0;
|
||||||
const maxIdx = markerKeys.length;
|
content.text = content.text.replace(
|
||||||
content.text = content.text.replace(/[\ue000-\uf8ff]/g, (match, offset) => {
|
new RegExp(`[\ue000-${String.fromCharCode((0xe000 + markerKeys.length) - 1)}]`, 'g'),
|
||||||
|
(match, offset) => {
|
||||||
const idx = match.charCodeAt(0) - 0xe000;
|
const idx = match.charCodeAt(0) - 0xe000;
|
||||||
if (idx >= maxIdx) {
|
|
||||||
return match;
|
|
||||||
}
|
|
||||||
const markerKey = markerKeys[idx];
|
const markerKey = markerKeys[idx];
|
||||||
const discussion = content.discussions[markerKey.id];
|
const discussion = content.discussions[markerKey.id];
|
||||||
if (discussion) {
|
if (discussion) {
|
||||||
@ -80,16 +79,18 @@ function restoreDiscussionOffsets(content, markerKeys) {
|
|||||||
count += 1;
|
count += 1;
|
||||||
return '';
|
return '';
|
||||||
});
|
});
|
||||||
|
// Sanitize offsets
|
||||||
Object.keys(content.discussions).forEach((discussionId) => {
|
Object.keys(content.discussions).forEach((discussionId) => {
|
||||||
const discussion = content.discussions[discussionId];
|
const discussion = content.discussions[discussionId];
|
||||||
if (discussion.start === undefined) {
|
if (discussion.start === undefined) {
|
||||||
discussion.start = discussion.end || 0;
|
discussion.start = discussion.end || 0;
|
||||||
}
|
}
|
||||||
if (discussion.end === undefined) {
|
if (discussion.end === undefined || discussion.end < discussion.start) {
|
||||||
discussion.end = discussion.start;
|
discussion.end = discussion.start;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function mergeText(serverText, clientText, lastMergedText) {
|
function mergeText(serverText, clientText, lastMergedText) {
|
||||||
const serverClientDiffs = diffMatchPatch.diff_main(serverText, clientText);
|
const serverClientDiffs = diffMatchPatch.diff_main(serverText, clientText);
|
||||||
|
@ -493,8 +493,6 @@ const editorSvc = Object.assign(new Vue(), editorSvcDiscussions, editorSvcUtils,
|
|||||||
this.clEditor.on('contentChanged',
|
this.clEditor.on('contentChanged',
|
||||||
(content, diffs, sectionList) => onEditorChanged(sectionList));
|
(content, diffs, sectionList) => onEditorChanged(sectionList));
|
||||||
|
|
||||||
this.$emit('inited');
|
|
||||||
|
|
||||||
// clEditorSvc.setPreviewElt(element[0].querySelector('.preview__inner-2'))
|
// clEditorSvc.setPreviewElt(element[0].querySelector('.preview__inner-2'))
|
||||||
// var previewElt = element[0].querySelector('.preview')
|
// var previewElt = element[0].querySelector('.preview')
|
||||||
// clEditorSvc.isPreviewTop = previewElt.scrollTop < 10
|
// clEditorSvc.isPreviewTop = previewElt.scrollTop < 10
|
||||||
@ -551,6 +549,7 @@ const editorSvc = Object.assign(new Vue(), editorSvcDiscussions, editorSvcUtils,
|
|||||||
() => this.measureSectionDimensions(false, true));
|
() => this.measureSectionDimensions(false, true));
|
||||||
|
|
||||||
this.initHighlighters();
|
this.initHighlighters();
|
||||||
|
this.$emit('inited');
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import EditorClassApplier from '../components/common/EditorClassApplier';
|
|||||||
import PreviewClassApplier from '../components/common/PreviewClassApplier';
|
import PreviewClassApplier from '../components/common/PreviewClassApplier';
|
||||||
|
|
||||||
let clEditor;
|
let clEditor;
|
||||||
|
// let discussionIds = {};
|
||||||
let discussionMarkers = {};
|
let discussionMarkers = {};
|
||||||
let markerKeys;
|
let markerKeys;
|
||||||
let markerIdxMap;
|
let markerIdxMap;
|
||||||
@ -137,6 +138,25 @@ export default {
|
|||||||
isChangePatch = false;
|
isChangePatch = false;
|
||||||
});
|
});
|
||||||
clEditor.on('focus', () => store.commit('discussion/setNewCommentFocus', false));
|
clEditor.on('focus', () => store.commit('discussion/setNewCommentFocus', false));
|
||||||
|
|
||||||
|
// Track new discussions (not sure it's a good idea)
|
||||||
|
// store.watch(
|
||||||
|
// () => store.getters['content/current'].discussions,
|
||||||
|
// (discussions) => {
|
||||||
|
// const oldDiscussionIds = discussionIds;
|
||||||
|
// discussionIds = {};
|
||||||
|
// let hasNewDiscussion = false;
|
||||||
|
// Object.keys(discussions).forEach((discussionId) => {
|
||||||
|
// discussionIds[discussionId] = true;
|
||||||
|
// if (!oldDiscussionIds[discussionId]) {
|
||||||
|
// hasNewDiscussion = true;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// if (hasNewDiscussion) {
|
||||||
|
// const content = store.getters['content/current'];
|
||||||
|
// currentPatchableText = diffUtils.makePatchableText(content, markerKeys, markerIdxMap);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
},
|
},
|
||||||
initClEditorInternal(opts) {
|
initClEditorInternal(opts) {
|
||||||
const content = store.getters['content/current'];
|
const content = store.getters['content/current'];
|
||||||
|
@ -117,6 +117,12 @@ export default {
|
|||||||
getters.currentDiscussionComments[getters.currentDiscussionLastCommentId],
|
getters.currentDiscussionComments[getters.currentDiscussionLastCommentId],
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
cancelNewComment({ commit, getters }) {
|
||||||
|
commit('setIsCommenting', false);
|
||||||
|
if (!getters.currentDiscussion) {
|
||||||
|
commit('setCurrentDiscussionId', getters.nextDiscussionId);
|
||||||
|
}
|
||||||
|
},
|
||||||
createNewDiscussion({ commit, dispatch, rootGetters }, selection) {
|
createNewDiscussion({ commit, dispatch, rootGetters }, selection) {
|
||||||
const loginToken = rootGetters['data/loginToken'];
|
const loginToken = rootGetters['data/loginToken'];
|
||||||
if (!loginToken) {
|
if (!loginToken) {
|
||||||
|
Loading…
Reference in New Issue
Block a user