From 9ebafddac21d99f6772d38cdce97d8939317d376 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 14 Jul 2021 21:51:30 +0200 Subject: [PATCH] :sparkles: Make last font used the default for next text box --- common/src/app/common/text.cljc | 3 ++- frontend/src/app/main/data/workspace.cljs | 18 ++++++++++++++---- .../src/app/main/data/workspace/texts.cljs | 14 +++++++++----- .../src/app/main/ui/shapes/text/styles.cljs | 4 ++-- .../workspace/sidebar/options/menus/text.cljs | 2 +- .../workspace/sidebar/options/shapes/text.cljs | 2 ++ frontend/src/app/util/text_editor_impl.js | 2 +- 7 files changed, 31 insertions(+), 14 deletions(-) diff --git a/common/src/app/common/text.cljc b/common/src/app/common/text.cljc index 9f184e7e9..f4c450f1a 100644 --- a/common/src/app/common/text.cljc +++ b/common/src/app/common/text.cljc @@ -64,7 +64,8 @@ (defn ^boolean is-text-node? [node] - (string? (:text node))) + (and (string? (:text node)) + (not= (:text node) ""))) (defn ^boolean is-paragraph-node? [node] diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 7c0a57c7d..8ec75ebf3 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -207,7 +207,16 @@ :workspace-file :workspace-project :workspace-media-objects - :workspace-persistence)) + :workspace-persistence + :workspace-local + :workspace-data + :workspace-editor-state + :workspace-undo + :current-file-id + :current-project-id + :workspace-layout + :workspace-libraries + :workspace-presence)) ptk/WatchEvent (watch [_ _ _] @@ -242,9 +251,10 @@ (update [_ state] (let [page-id (or page-id (get-in state [:workspace-data :pages 0])) local (-> (:workspace-local state) - (dissoc :edition) - (dissoc :edit-path) - (dissoc :selected))] + (dissoc + :edition + :edit-path + :selected))] (-> state (assoc-in [:workspace-cache page-id] local) (dissoc :current-page-id :workspace-local :trimmed-page :workspace-drawing)))))) diff --git a/frontend/src/app/main/data/workspace/texts.cljs b/frontend/src/app/main/data/workspace/texts.cljs index 11dad4b70..390e415db 100644 --- a/frontend/src/app/main/data/workspace/texts.cljs +++ b/frontend/src/app/main/data/workspace/texts.cljs @@ -75,11 +75,14 @@ (ptk/reify ::initialize-editor-state ptk/UpdateEvent (update [_ state] - (update-in state [:workspace-editor-state id] - (fn [_] - (ted/create-editor-state - (some->> content ted/import-content) - decorator)))) + (let [text-state (some->> content ted/import-content) + attrs (get-in state [:workspace-local :defaults :font]) + + editor (cond-> (ted/create-editor-state text-state decorator) + (and (nil? content) (some? attrs)) + (ted/update-editor-current-block-data attrs))] + (-> state + (assoc-in [:workspace-editor-state id] editor)))) ptk/WatchEvent (watch [_ _ stream] @@ -326,3 +329,4 @@ (assoc-in state [:workspace-local :defaults :font] data)))) + diff --git a/frontend/src/app/main/ui/shapes/text/styles.cljs b/frontend/src/app/main/ui/shapes/text/styles.cljs index 9d247e13f..ec76c8f61 100644 --- a/frontend/src/app/main/ui/shapes/text/styles.cljs +++ b/frontend/src/app/main/ui/shapes/text/styles.cljs @@ -47,8 +47,8 @@ text-align (:text-align data "start") grow-type (:grow-type shape) - base #js {:fontSize (str (:font-size txt/default-text-attrs) "px") - :lineHeight (:line-height txt/default-text-attrs) + base #js {:fontSize (str (:font-size data (:font-size txt/default-text-attrs)) "px") + :lineHeight (:line-height data (:line-height txt/default-text-attrs)) :margin "inherit"}] (cond-> base (some? line-height) (obj/set! "lineHeight" line-height) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/text.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/text.cljs index 6bd83ade7..ac2dc026f 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/text.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/text.cljs @@ -222,7 +222,7 @@ (mf/use-callback (mf/deps values) (fn [id attrs] - (st/emit! (dwt/save-font (merge values attrs))) + (st/emit! (dwt/save-font (merge txt/default-text-attrs values attrs))) (let [attrs (select-keys attrs root-attrs)] (when-not (empty? attrs) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/text.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/text.cljs index 298983432..a15c66e02 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/text.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/text.cljs @@ -9,6 +9,7 @@ [app.common.data :as d] [app.main.data.workspace.texts :as dwt] [app.main.refs :as refs] + [app.main.ui.workspace.sidebar.options.menus.fill :refer [fill-attrs]] [app.main.ui.workspace.sidebar.options.menus.blur :refer [blur-menu]] [app.main.ui.workspace.sidebar.options.menus.constraints :refer [constraint-attrs constraints-menu]] [app.main.ui.workspace.sidebar.options.menus.fill :refer [fill-menu]] @@ -42,6 +43,7 @@ text-values (d/merge (select-keys shape [:grow-type]) + (select-keys shape fill-attrs) (dwt/current-root-values {:shape shape :attrs root-attrs}) diff --git a/frontend/src/app/util/text_editor_impl.js b/frontend/src/app/util/text_editor_impl.js index 6eb1983cb..3c735b97c 100644 --- a/frontend/src/app/util/text_editor_impl.js +++ b/frontend/src/app/util/text_editor_impl.js @@ -122,7 +122,7 @@ export function applyInlineStyle(state, styles) { let selection = state.getSelection(); if (selection.isCollapsed()) { - selection = selection.set("anchorOffset", 0); + selection = getSelectAllSelection(state); } let content = null;