Make last font used the default for next text box

This commit is contained in:
alonso.torres 2021-07-14 21:51:30 +02:00
parent 26467187c4
commit 9ebafddac2
7 changed files with 31 additions and 14 deletions

View file

@ -64,7 +64,8 @@
(defn ^boolean is-text-node? (defn ^boolean is-text-node?
[node] [node]
(string? (:text node))) (and (string? (:text node))
(not= (:text node) "")))
(defn ^boolean is-paragraph-node? (defn ^boolean is-paragraph-node?
[node] [node]

View file

@ -207,7 +207,16 @@
:workspace-file :workspace-file
:workspace-project :workspace-project
:workspace-media-objects :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 ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
@ -242,9 +251,10 @@
(update [_ state] (update [_ state]
(let [page-id (or page-id (get-in state [:workspace-data :pages 0])) (let [page-id (or page-id (get-in state [:workspace-data :pages 0]))
local (-> (:workspace-local state) local (-> (:workspace-local state)
(dissoc :edition) (dissoc
(dissoc :edit-path) :edition
(dissoc :selected))] :edit-path
:selected))]
(-> state (-> state
(assoc-in [:workspace-cache page-id] local) (assoc-in [:workspace-cache page-id] local)
(dissoc :current-page-id :workspace-local :trimmed-page :workspace-drawing)))))) (dissoc :current-page-id :workspace-local :trimmed-page :workspace-drawing))))))

View file

@ -75,11 +75,14 @@
(ptk/reify ::initialize-editor-state (ptk/reify ::initialize-editor-state
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(update-in state [:workspace-editor-state id] (let [text-state (some->> content ted/import-content)
(fn [_] attrs (get-in state [:workspace-local :defaults :font])
(ted/create-editor-state
(some->> content ted/import-content) editor (cond-> (ted/create-editor-state text-state decorator)
decorator)))) (and (nil? content) (some? attrs))
(ted/update-editor-current-block-data attrs))]
(-> state
(assoc-in [:workspace-editor-state id] editor))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ stream] (watch [_ _ stream]
@ -326,3 +329,4 @@
(assoc-in state (assoc-in state
[:workspace-local :defaults :font] [:workspace-local :defaults :font]
data)))) data))))

View file

@ -47,8 +47,8 @@
text-align (:text-align data "start") text-align (:text-align data "start")
grow-type (:grow-type shape) grow-type (:grow-type shape)
base #js {:fontSize (str (:font-size txt/default-text-attrs) "px") base #js {:fontSize (str (:font-size data (:font-size txt/default-text-attrs)) "px")
:lineHeight (:line-height txt/default-text-attrs) :lineHeight (:line-height data (:line-height txt/default-text-attrs))
:margin "inherit"}] :margin "inherit"}]
(cond-> base (cond-> base
(some? line-height) (obj/set! "lineHeight" line-height) (some? line-height) (obj/set! "lineHeight" line-height)

View file

@ -222,7 +222,7 @@
(mf/use-callback (mf/use-callback
(mf/deps values) (mf/deps values)
(fn [id attrs] (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)] (let [attrs (select-keys attrs root-attrs)]
(when-not (empty? attrs) (when-not (empty? attrs)

View file

@ -9,6 +9,7 @@
[app.common.data :as d] [app.common.data :as d]
[app.main.data.workspace.texts :as dwt] [app.main.data.workspace.texts :as dwt]
[app.main.refs :as refs] [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.blur :refer [blur-menu]]
[app.main.ui.workspace.sidebar.options.menus.constraints :refer [constraint-attrs constraints-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]] [app.main.ui.workspace.sidebar.options.menus.fill :refer [fill-menu]]
@ -42,6 +43,7 @@
text-values (d/merge text-values (d/merge
(select-keys shape [:grow-type]) (select-keys shape [:grow-type])
(select-keys shape fill-attrs)
(dwt/current-root-values (dwt/current-root-values
{:shape shape {:shape shape
:attrs root-attrs}) :attrs root-attrs})

View file

@ -122,7 +122,7 @@ export function applyInlineStyle(state, styles) {
let selection = state.getSelection(); let selection = state.getSelection();
if (selection.isCollapsed()) { if (selection.isCollapsed()) {
selection = selection.set("anchorOffset", 0); selection = getSelectAllSelection(state);
} }
let content = null; let content = null;