From 477e2464b810e910a23fcbdcd8e6c25480610321 Mon Sep 17 00:00:00 2001 From: barlas <yannisbarlas@gmail.com> Date: Mon, 20 Mar 2017 18:42:36 +0200 Subject: [PATCH] selection around notes does not open tooltip --- .../elements/note/EditNoteTool.js | 34 ++++++++++++++----- .../SimpleEditor/elements/note/note.scss | 11 +++--- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/app/components/SimpleEditor/elements/note/EditNoteTool.js b/app/components/SimpleEditor/elements/note/EditNoteTool.js index 34a4777..0d4569d 100644 --- a/app/components/SimpleEditor/elements/note/EditNoteTool.js +++ b/app/components/SimpleEditor/elements/note/EditNoteTool.js @@ -1,6 +1,10 @@ import { each, includes, keys } from 'lodash' -import { documentHelpers, Tool, ProseEditorConfigurator as Configurator, - EditorSession } from 'substance' +import { + documentHelpers, + EditorSession, + ProseEditorConfigurator as Configurator, + Tool +} from 'substance' import MiniEditor from '../../miniEditor/miniEditor' import config from '../../miniEditor/config' @@ -8,7 +12,6 @@ import Importer from '../../SimpleEditorImporter' import SimpleExporter from '../../SimpleEditorExporter' class EditNoteTool extends Tool { - constructor (props) { super(props) this.saveNote = this.saveNote.bind(this) @@ -16,12 +19,16 @@ class EditNoteTool extends Tool { render ($$) { const miniEditorSession = this._initMiniEditor() - let el = $$('div').addClass('sc-edit-note-tool') const selected = this.getSelection() + + let el = $$('div').addClass('sc-edit-note-tool') + if (!selected.node) return el + el.append($$(MiniEditor, { editorSession: miniEditorSession })) + return el } @@ -87,18 +94,29 @@ class EditNoteTool extends Tool { const session = this.context.editorSession const sel = session.getSelection() - const note = documentHelpers.getPropertyAnnotationsForSelection( + const notes = documentHelpers.getPropertyAnnotationsForSelection( session.getDocument(), sel, { type: 'note' } ) + const note = notes[0] + let show = false + + if (typeof note !== 'undefined') { + if ((sel.start.offset === note.start.offset && + sel.end.offset === note.end.offset)) { + show = true + } + } + // disable when larger selection that just includes a note as well - const selectionLength = (sel.end.offset - sel.start.offset === 1) + // const selectionLength = (sel.end.offset - sel.start.offset === 1) + // if (sel.end.offset - sel.) - if (typeof note[0] !== 'undefined' && selectionLength) { + if (show) { return { - node: note[0] + node: note } } else { return { diff --git a/app/components/SimpleEditor/elements/note/note.scss b/app/components/SimpleEditor/elements/note/note.scss index fb665ba..5e54d1c 100644 --- a/app/components/SimpleEditor/elements/note/note.scss +++ b/app/components/SimpleEditor/elements/note/note.scss @@ -1,15 +1,18 @@ $gray: #eee; $red: #591818; -// .hidden { -// display: none; -// } + .sc-prose-editor { counter-reset: note; + .sm-note { + display: inline-block; + } + .sc-note { color: $red; - display: inline-block; // TODO -- is this correct? + display: block; font-weight: bold; + user-select: initial; } .sc-note::after { -- GitLab