0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-08 16:18:11 -05:00

Use tabulators to navigate layers

This commit is contained in:
Alejandro Alonso 2023-03-16 07:25:19 +01:00 committed by Alonso Torres
parent 25014a81c3
commit fbf06a4de0
9 changed files with 121 additions and 16 deletions

View file

@ -10,6 +10,7 @@
- Allow for absolute positioned elements inside layout [Taiga #4834](https://tree.taiga.io/project/penpot/us/4834) - Allow for absolute positioned elements inside layout [Taiga #4834](https://tree.taiga.io/project/penpot/us/4834)
- Add z-index option for flex layout items [Taiga #2980](https://tree.taiga.io/project/penpot/us/2980) - Add z-index option for flex layout items [Taiga #2980](https://tree.taiga.io/project/penpot/us/2980)
- Scale content proportionally affects strokes, shadows, blurs and corners [Taiga #1951](https://tree.taiga.io/project/penpot/us/1951) - Scale content proportionally affects strokes, shadows, blurs and corners [Taiga #1951](https://tree.taiga.io/project/penpot/us/1951)
- Use tabulators to navigate layers [Taiga #5010](https://tree.taiga.io/project/penpot/issue/5010)
### :bug: Bugs fixed ### :bug: Bugs fixed

View file

@ -7,7 +7,7 @@
(ns app.main.data.shortcuts (ns app.main.data.shortcuts
(:refer-clojure :exclude [meta reset!]) (:refer-clojure :exclude [meta reset!])
(:require (:require
["mousetrap" :as mousetrap] ["./shortcuts_impl.js$default" :as mousetrap]
[app.common.logging :as log] [app.common.logging :as log]
[app.common.spec :as us] [app.common.spec :as us]
[app.config :as cf] [app.config :as cf]
@ -32,6 +32,7 @@
(def up-arrow "\u2191") (def up-arrow "\u2191")
(def right-arrow "\u2192") (def right-arrow "\u2192")
(def down-arrow "\u2193") (def down-arrow "\u2193")
(def tab "tab")
(defn c-mod (defn c-mod
"Adds the control/command modifier to a shortcuts depending on the "Adds the control/command modifier to a shortcuts depending on the

View file

@ -0,0 +1,27 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright (c) KALEIDOS INC
*/
"use strict";
import Mousetrap from 'mousetrap'
const target = Mousetrap.prototype || Mousetrap;
target.stopCallback = function(e, element, combo) {
// if the element has the class "mousetrap" then no need to stop
if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) {
return false;
}
// stop for input, select, textarea and button
return element.tagName == 'INPUT' ||
element.tagName == 'SELECT' ||
element.tagName == 'TEXTAREA' ||
element.tagName == 'BUTTON' ||
(element.contentEditable && element.contentEditable == 'true');
}
export default Mousetrap;

View file

@ -2046,6 +2046,8 @@
(dm/export dws/select-all) (dm/export dws/select-all)
(dm/export dws/select-inside-group) (dm/export dws/select-inside-group)
(dm/export dws/select-shape) (dm/export dws/select-shape)
(dm/export dws/select-prev-shape)
(dm/export dws/select-next-shape)
(dm/export dws/shift-select-shapes) (dm/export dws/shift-select-shapes)
;; Highlight ;; Highlight

View file

@ -131,6 +131,55 @@
objects (wsh/lookup-page-objects state page-id)] objects (wsh/lookup-page-objects state page-id)]
(rx/of (dwc/expand-all-parents [id] objects))))))) (rx/of (dwc/expand-all-parents [id] objects)))))))
(defn select-prev-shape
([]
(ptk/reify ::select-prev-shape
ptk/WatchEvent
(watch [_ state _]
(let [selected (wsh/lookup-selected state)
count-selected (count selected)
first-selected (first selected)
page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
current (get objects first-selected)
parent (get objects (:parent-id current))
sibling-ids (:shapes parent)
current-index (d/index-of sibling-ids first-selected)
sibling (if (= (dec (count sibling-ids)) current-index)
(first sibling-ids)
(nth sibling-ids (inc current-index)))]
(cond
(= 1 count-selected)
(rx/of (select-shape sibling))
(> count-selected 1)
(rx/of (select-shape first-selected))))))))
(defn select-next-shape
([]
(ptk/reify ::select-next-shape
ptk/WatchEvent
(watch [_ state _]
(let [selected (wsh/lookup-selected state)
count-selected (count selected)
first-selected (first selected)
page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
current (get objects first-selected)
parent (get objects (:parent-id current))
sibling-ids (:shapes parent)
current-index (d/index-of sibling-ids first-selected)
sibling (if (= 0 current-index)
(last sibling-ids)
(nth sibling-ids (dec current-index)))]
(cond
(= 1 count-selected)
(rx/of (select-shape sibling))
(> count-selected 1)
(rx/of (select-shape first-selected))))))))
(defn deselect-shape (defn deselect-shape
[id] [id]
(us/verify ::us/uuid id) (us/verify ::us/uuid id)

View file

@ -495,8 +495,19 @@
:subsections [:navigation-workspace] :subsections [:navigation-workspace]
:fn #(st/emit! (dw/go-to-dashboard))} :fn #(st/emit! (dw/go-to-dashboard))}
:select-prev {:tooltip (ds/shift "tab")
:command "shift+tab"
:subsections [:navigation-workspace]
:fn #(st/emit! (dw/select-prev-shape))}
:select-next {:tooltip ds/tab
:command "tab"
:subsections [:navigation-workspace]
:fn #(st/emit! (dw/select-next-shape))}
;; SHAPE ;; SHAPE
:bool-union {:tooltip (ds/meta (ds/alt "U")) :bool-union {:tooltip (ds/meta (ds/alt "U"))
:command (ds/c-mod "alt+u") :command (ds/c-mod "alt+u")
:subsections [:shape] :subsections [:shape]

View file

@ -143,6 +143,8 @@
;; shortcuts.open-color-picker ;; shortcuts.open-color-picker
;; shortcuts.open-comments ;; shortcuts.open-comments
;; shortcuts.open-dashboard ;; shortcuts.open-dashboard
;; shortcuts.select-prev
;; shortcuts.select-next
;; shortcuts.open-inspect ;; shortcuts.open-inspect
;; shortcuts.open-interactions ;; shortcuts.open-interactions
;; shortcuts.open-viewer ;; shortcuts.open-viewer

View file

@ -2458,6 +2458,12 @@ msgstr "Go to viewer comment section"
msgid "shortcuts.open-dashboard" msgid "shortcuts.open-dashboard"
msgstr "Go to dashboard" msgstr "Go to dashboard"
msgid "shortcuts.select-next"
msgstr "Select next layer"
msgid "shortcuts.select-prev"
msgstr "Select previous layer"
msgid "shortcuts.open-inspect" msgid "shortcuts.open-inspect"
msgstr "Go to viewer inspect section" msgstr "Go to viewer inspect section"

View file

@ -2603,6 +2603,12 @@ msgstr "Comentarios"
msgid "shortcuts.open-dashboard" msgid "shortcuts.open-dashboard"
msgstr "Ir al dashboard" msgstr "Ir al dashboard"
msgid "shortcuts.select-next"
msgstr "Seleccionar capa siguiente"
msgid "shortcuts.select-prev"
msgstr "Seleccionar capa anterior"
msgid "shortcuts.open-inspect" msgid "shortcuts.open-inspect"
msgstr "Ir al inspector" msgstr "Ir al inspector"