Skip to content

Commit 5cb3152

Browse files
committed
fix: tab keypress and non breaking space
1 parent 51b82f7 commit 5cb3152

File tree

5 files changed

+72
-22
lines changed

5 files changed

+72
-22
lines changed

packages/pluggableWidgets/rich-text-web/src/components/EditorWrapper.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function EditorWrapperInner(props: EditorWrapperProps): ReactElement {
153153
}
154154
}}
155155
spellCheck={props.spellCheck}
156-
tabIndex={tabIndex}
156+
tabIndex={tabIndex ?? -1}
157157
{...actionEvents}
158158
>
159159
<If condition={toolbarLocation === "auto"}>
@@ -202,6 +202,7 @@ function EditorWrapperInner(props: EditorWrapperProps): ReactElement {
202202
formOrientation={formOrientation}
203203
/>
204204
</div>
205+
205206
<div
206207
className={classNames("widget-rich-text-footer", { "hide-status-bar": !enableStatusBar })}
207208
tabIndex={-1}

packages/pluggableWidgets/rich-text-web/src/ui/RichText.scss

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ $rte-brand-primary: #264ae5;
8888
display: none;
8989
}
9090

91-
.widget-rich-text-footer {
91+
&-footer {
9292
align-items: center;
93-
border-top: 1px solid var(--border-color-default, $rte-border-color-default);
9493
color: var(--font-color-detail);
9594
display: flex;
9695
flex: 0 0 auto;
@@ -102,9 +101,12 @@ $rte-brand-primary: #264ae5;
102101
text-transform: none;
103102
justify-content: end;
104103

105-
&.hide-status-bar {
106-
border-top: none;
107-
height: 0;
104+
&:not(.hide-status-bar) {
105+
border-top: 1px solid var(--border-color-default, $rte-border-color-default);
106+
}
107+
108+
&:focus-within {
109+
border-top: 1px solid var(--form-input-border-focus-color, var(--brand-primary, $rte-brand-primary));
108110
}
109111
}
110112

packages/pluggableWidgets/rich-text-web/src/utils/MxQuill.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function convertHTML(blot: Blot, index: number, length: number, isRoot = false):
174174
}
175175
if (blot instanceof TextBlot) {
176176
const escapedText = escapeText(blot.value().slice(index, index + length));
177-
return escapedText.replaceAll(" ", "&nbsp;");
177+
return escapedText;
178178
}
179179
if (blot instanceof ParentBlot) {
180180
// TODO fix API

packages/pluggableWidgets/rich-text-web/src/utils/modules/keyboard.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
exitFullscreenKeyboardHandler,
55
gotoStatusBarKeyboardHandler,
66
gotoToolbarKeyboardHandler,
7+
moveIndent,
8+
moveOutdent,
79
movePrevFocus,
810
shiftEnterKeyKeyboardHandler
911
} from "./toolbarHandlers";
@@ -30,9 +32,21 @@ export function getKeyboardBindings(): Record<string, unknown> {
3032
shiftTab: {
3133
key: "Tab",
3234
shiftKey: true,
33-
collapsed: true,
3435
handler: movePrevFocus
3536
},
37+
outdent: {
38+
key: "Tab",
39+
shiftKey: true,
40+
format: ["blockquote", "indent", "list"],
41+
// highlight tab or tab at beginning of list, indent or blockquote
42+
handler: moveOutdent
43+
},
44+
indent: {
45+
// highlight tab or tab at beginning of list, indent or blockquote
46+
key: "Tab",
47+
format: ["blockquote", "indent", "list"],
48+
handler: moveIndent
49+
},
3650
nextFocusTab: {
3751
key: "F11",
3852
altKey: true,

packages/pluggableWidgets/rich-text-web/src/utils/modules/toolbarHandlers.ts

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import { Scope } from "parchment";
77
import { ACTION_DISPATCHER } from "../helpers";
88
import { SET_FULLSCREEN_ACTION } from "../../store/store";
99

10+
function returnWithStopPropagation(context: Context): boolean {
11+
context.event.stopPropagation();
12+
context.event.preventDefault();
13+
return true;
14+
}
15+
1016
/**
1117
* give custom indent handler to use our custom "indent-left" and "indent-right" formats (formats/indent.ts)
1218
*/
@@ -80,13 +86,36 @@ export function shiftEnterKeyKeyboardHandler(this: Keyboard, range: Range, conte
8086
}
8187

8288
export function movePrevFocus(this: Keyboard, range: Range, context: Context): any {
83-
if (context.format.table || context.format.indent || context.format.list || context.format.blockquote) {
84-
context.event.stopPropagation();
85-
context.event.preventDefault();
86-
return true;
89+
if (context.format.table) {
90+
return returnWithStopPropagation(context);
91+
} else if (context.collapsed) {
92+
if (context.format.indent || context.format.list || context.format.blockquote) {
93+
return returnWithStopPropagation(context);
94+
}
8795
}
8896

8997
gotoToolbarKeyboardHandler.call(this, range, context);
98+
return returnWithStopPropagation(context);
99+
}
100+
101+
// Copied from https://github.com/slab/quill/blob/539cbffd0a13b18e9c65eb84dd35e6596e403158/packages/quill/src/modules/keyboard.ts#L372
102+
// with added stopPropagation and preventDefault
103+
export function moveOutdent(this: Keyboard, _range: Range, context: Context): any {
104+
if (context.collapsed && context.offset !== 0) {
105+
return returnWithStopPropagation(context);
106+
}
107+
this.quill.format("indent", "-1", Quill.sources.USER);
108+
return !returnWithStopPropagation(context);
109+
}
110+
111+
// Copied from https://github.com/slab/quill/blob/539cbffd0a13b18e9c65eb84dd35e6596e403158/packages/quill/src/modules/keyboard.ts#L372
112+
// with added stopPropagation and preventDefault
113+
export function moveIndent(this: Keyboard, _range: Range, context: Context): any {
114+
if (context.collapsed && context.offset !== 0) {
115+
return returnWithStopPropagation(context);
116+
}
117+
this.quill.format("indent", "+1", Quill.sources.USER);
118+
return !returnWithStopPropagation(context);
90119
}
91120

92121
// focus to first toolbar button
@@ -99,7 +128,8 @@ export function gotoToolbarKeyboardHandler(this: Keyboard, _range: Range, contex
99128
if (toolbar) {
100129
(toolbar?.querySelector(".ql-formats button") as HTMLElement)?.focus();
101130
} else {
102-
this.quill.blur();
131+
// "widget-rich-text form-control"
132+
this.quill.container.parentElement?.parentElement?.parentElement?.focus();
103133
}
104134
}
105135

@@ -113,7 +143,8 @@ export function gotoStatusBarKeyboardHandler(this: Keyboard, _range: Range, cont
113143
if (statusBar) {
114144
(statusBar as HTMLElement)?.focus();
115145
} else {
116-
this.quill.blur();
146+
// "widget-rich-text form-control"
147+
this.quill.container.parentElement?.parentElement?.parentElement?.focus();
117148
}
118149
}
119150

@@ -124,14 +155,16 @@ export function addIndentText(this: Keyboard, range: Range, context: Context): b
124155
if (context.format.table) {
125156
return true;
126157
}
127-
this.quill.history.cutoff();
128-
const delta = new Delta().retain(range.index).delete(range.length).insert("\t");
129-
this.quill.updateContents(delta, Quill.sources.USER);
130-
this.quill.history.cutoff();
131-
this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
132-
context.event.stopPropagation();
133-
context.event.preventDefault();
134-
return false;
158+
if (context.collapsed && context.offset === 0) {
159+
return moveIndent.call(this, range, context);
160+
} else {
161+
this.quill.history.cutoff();
162+
const delta = new Delta().retain(range.index).delete(range.length).insert("\t");
163+
this.quill.updateContents(delta, Quill.sources.USER);
164+
this.quill.history.cutoff();
165+
this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
166+
return returnWithStopPropagation(context);
167+
}
135168
}
136169

137170
/**

0 commit comments

Comments
 (0)