Fix some issues with the Tag Editor (#2215)

* Prevent global focus border on tag-input

* Fix margin issues with tag editor

* Remove redundant autocomplete call

that caused the addition of an empty tag when tag suggestions were selected with the Enter key.

* Prevent input text from overlapping with newly added tags

... at least when they're selected from the autocomplete list via mouse. If they're selected via keyboard, there's still an overlapping issue.

* Fix error on updateSuggestions

* Hide empty tag

* Make double-click to collapse/expand translatable
This commit is contained in:
Matthias Metelka 2022-11-27 01:45:33 +01:00 committed by GitHub
parent 8f2f62c466
commit 6c6a10c142
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 16 deletions

View file

@ -15,7 +15,8 @@ editing-customize-card-templates = Customize Card Templates
editing-customize-fields = Customize Fields editing-customize-fields = Customize Fields
editing-cut = Cut editing-cut = Cut
editing-double-click-image = double-click image editing-double-click-image = double-click image
editing-double-click-to-expand = (double-click to expand) editing-double-click-to-expand = double-click to expand
editing-double-click-to-collapse = double-click to collapse
editing-edit-current = Edit Current editing-edit-current = Edit Current
editing-edit-html = Edit HTML editing-edit-html = Edit HTML
editing-fields = Fields editing-fields = Fields

View file

@ -49,6 +49,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import PaneContent from "../components/PaneContent.svelte"; import PaneContent from "../components/PaneContent.svelte";
import { ResizablePane } from "../components/types"; import { ResizablePane } from "../components/types";
import { bridgeCommand } from "../lib/bridgecommand"; import { bridgeCommand } from "../lib/bridgecommand";
import * as tr from "../lib/ftl";
import { TagEditor } from "../tag-editor"; import { TagEditor } from "../tag-editor";
import TagAddButton from "../tag-editor/tag-options-button/TagAddButton.svelte"; import TagAddButton from "../tag-editor/tag-options-button/TagAddButton.svelte";
import { ChangeTimer } from "./change-timer"; import { ChangeTimer } from "./change-timer";
@ -560,7 +561,9 @@ the AddCards dialog) should be implemented in the user of this component.
<HorizontalResizer <HorizontalResizer
panes={[fieldsPane, tagsPane]} panes={[fieldsPane, tagsPane]}
showIndicator={$tagsCollapsed || snapTags} showIndicator={$tagsCollapsed || snapTags}
tip={`Double click to ${$tagsCollapsed ? "expand" : "collapse"} tag editor`} tip={$tagsCollapsed
? tr.editingDoubleClickToExpand()
: tr.editingDoubleClickToCollapse()}
{clientHeight} {clientHeight}
bind:this={lowerResizer} bind:this={lowerResizer}
on:dblclick={() => snapResizer(!$tagsCollapsed)} on:dblclick={() => snapResizer(!$tagsCollapsed)}
@ -575,7 +578,7 @@ the AddCards dialog) should be implemented in the user of this component.
}} }}
keyCombination="Control+Shift+T" keyCombination="Control+Shift+T"
> >
{@html tagAmount > 0 ? `${tagAmount} Tags` : ""} {@html tagAmount > 0 ? `${tagAmount} ${tr.editingTags()}` : ""}
</TagAddButton> </TagAddButton>
</div> </div>
</HorizontalResizer> </HorizontalResizer>

View file

@ -324,7 +324,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<HandleLabel> <HandleLabel>
{#if isSizeConstrained} {#if isSizeConstrained}
<span>{tr.editingDoubleClickToExpand()}</span> <span>{`(${tr.editingDoubleClickToExpand()})`}</span>
{:else} {:else}
<span>{actualWidth}&times;{actualHeight}</span> <span>{actualWidth}&times;{actualHeight}</span>
{#if customDimensions} {#if customDimensions}

View file

@ -56,6 +56,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
.tag { .tag {
@include button.base($with-active: false, $with-disabled: false); @include button.base($with-active: false, $with-disabled: false);
vertical-align: middle;
font-size: var(--font-size); font-size: var(--font-size);
padding: 0; padding: 0;

View file

@ -77,7 +77,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
function updateSuggestions(): void { function updateSuggestions(): void {
const activeTag = tagTypes[active!]; const activeTag = tagTypes[active!];
const activeName = activeTag.name; const activeName = activeTag!.name;
autocompleteDisabled = activeName.length === 0; autocompleteDisabled = activeName.length === 0;
@ -125,15 +125,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
export function appendEmptyTag(): void { export function appendEmptyTag(): void {
// used by tag badge and tag spacer // used by tag badge and tag spacer
deselect(); deselect();
const tagsHadFocus = active === null;
active = null;
const lastTag = tagTypes[tagTypes.length - 1]; const lastTag = tagTypes[tagTypes.length - 1];
if (!lastTag || lastTag.name.length > 0) { if (!lastTag || lastTag.name.length > 0) {
appendTagAndFocusAt(tagTypes.length - 1, ""); appendTagAndFocusAt(tagTypes.length - 1, "");
} }
const tagsHadFocus = active === null;
active = null;
if (tagsHadFocus) { if (tagsHadFocus) {
decideNextActive(); decideNextActive();
} }
@ -163,11 +163,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
const splitOff = activeName.slice(end); const splitOff = activeName.slice(end);
activeName = current; activeName = current;
active = null;
// await tag to update its name, so it can normalize correctly // await tag to update its name, so it can normalize correctly
await tick(); await tick();
appendTagAndFocusAt(index, splitOff); appendTagAndFocusAt(index, splitOff);
active = null;
await tick(); await tick();
if (index === active) { if (index === active) {
@ -292,7 +292,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
break; break;
case "Enter": case "Enter":
autocomplete.chooseSelected();
event.preventDefault(); event.preventDefault();
break; break;
} }
@ -392,7 +391,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
$: shortenTags = shortenTags || assumedRows > 2; $: shortenTags = shortenTags || assumedRows > 2;
$: anyTagsSelected = tagTypes.some((tag) => tag.selected); $: anyTagsSelected = tagTypes.some((tag) => tag.selected);
$: dispatch("heightChange", { height: height * 1.15 }); $: dispatch("heightChange", { height: height + 1 });
</script> </script>
{#if anyTagsSelected} {#if anyTagsSelected}
@ -410,6 +409,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
on:tagdelete={deleteSelectedTags} on:tagdelete={deleteSelectedTags}
on:tagappend={appendEmptyTag} on:tagappend={appendEmptyTag}
{keyCombination} {keyCombination}
--icon-align="baseline"
/> />
{#each tagTypes as tag, index (tag.id)} {#each tagTypes as tag, index (tag.id)}
@ -518,6 +518,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
.hide-tag :global(.tag) { .hide-tag :global(.tag) {
opacity: 0; visibility: hidden;
} }
</style> </style>

View file

@ -280,6 +280,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
.tag-input { .tag-input {
/* recreates positioning of Tag component /* recreates positioning of Tag component
* so that the text does not move when accepting */ * so that the text does not move when accepting */
border-left: 1px solid transparent; border: 1px solid transparent !important;
} }
</style> </style>

View file

@ -2,12 +2,15 @@
Copyright: Ankitects Pty Ltd and contributors Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<div class="tag-spacer" on:click /> <div class="tag-spacer" on:click>
<br />
</div>
<style lang="scss"> <style lang="scss">
.tag-spacer { .tag-spacer {
cursor: text; cursor: text;
flex-grow: 1; flex-grow: 1;
align-self: stretch; align-self: stretch;
margin-top: 3px;
} }
</style> </style>

View file

@ -63,7 +63,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<svelte:body on:keydown={setControlShift} on:keyup={setControlShift} /> <svelte:body on:keydown={setControlShift} on:keyup={setControlShift} />
<div class:select-mode={selectMode} class:night-mode={$pageTheme.isDark}> <div
class:select-mode={selectMode}
class:night-mode={$pageTheme.isDark}
class:empty={name === ""}
>
{#if active} {#if active}
<Tag class={className} on:mousemove={setControlShift} on:click={onClick}> <Tag class={className} on:mousemove={setControlShift} on:click={onClick}>
{name} {name}
@ -119,4 +123,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
background-color: $white-translucent; background-color: $white-translucent;
} }
} }
.empty {
visibility: hidden;
}
</style> </style>

View file

@ -178,7 +178,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
/* Make sure that text in TagInput perfectly overlaps with Tag */ /* Make sure that text in TagInput perfectly overlaps with Tag */
border-left: 1px solid transparent; border-left: 1px solid transparent;
border-top: 2px solid transparent; border-bottom: 1px solid transparent;
} }
.autocomplete-menu { .autocomplete-menu {