This repository was archived by the owner on Sep 11, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +15
-3
lines changed
src/components/views/rooms/wysiwyg_composer
test/components/views/rooms/wysiwyg_composer/components Expand file tree Collapse file tree 4 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -23,11 +23,15 @@ function setSelectionContext(composerContext: ComposerContextState): void {
2323 const selection = document . getSelection ( ) ;
2424
2525 if ( selection ) {
26+ const range = selection . getRangeAt ( 0 ) ;
27+ const isForward = range . startContainer === selection . anchorNode && range . startOffset === selection . anchorOffset ;
28+
2629 composerContext . selection = {
2730 anchorNode : selection . anchorNode ,
2831 anchorOffset : selection . anchorOffset ,
2932 focusNode : selection . focusNode ,
3033 focusOffset : selection . focusOffset ,
34+ isForward,
3135 } ;
3236 }
3337}
Original file line number Diff line number Diff line change @@ -19,4 +19,6 @@ export type ComposerFunctions = {
1919 insertText : ( text : string ) => void ;
2020} ;
2121
22- export type SubSelection = Pick < Selection , "anchorNode" | "anchorOffset" | "focusNode" | "focusOffset" > ;
22+ export type SubSelection = Pick < Selection , "anchorNode" | "anchorOffset" | "focusNode" | "focusOffset" > & {
23+ isForward : boolean ;
24+ } ;
Original file line number Diff line number Diff line change @@ -19,9 +19,14 @@ import { SubSelection } from "../types";
1919export function setSelection ( selection : SubSelection ) : Promise < void > {
2020 if ( selection . anchorNode && selection . focusNode ) {
2121 const range = new Range ( ) ;
22- range . setStart ( selection . anchorNode , selection . anchorOffset ) ;
23- range . setEnd ( selection . focusNode , selection . focusOffset ) ;
2422
23+ if ( selection . isForward ) {
24+ range . setStart ( selection . anchorNode , selection . anchorOffset ) ;
25+ range . setEnd ( selection . focusNode , selection . focusOffset ) ;
26+ } else {
27+ range . setStart ( selection . focusNode , selection . focusOffset ) ;
28+ range . setEnd ( selection . anchorNode , selection . anchorOffset ) ;
29+ }
2530 document . getSelection ( ) ?. removeAllRanges ( ) ;
2631 document . getSelection ( ) ?. addRange ( range ) ;
2732 }
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ describe("LinkModal", () => {
3535 anchorNode : null ,
3636 focusOffset : 3 ,
3737 anchorOffset : 4 ,
38+ isForward : true ,
3839 } ;
3940
4041 const customRender = ( isTextEnabled : boolean , onClose : ( ) => void , isEditing = false ) => {
You can’t perform that action at this time.
0 commit comments