File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed
app/assets/javascripts/discourse/app/static/prosemirror/core Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 8
8
import { redo , undo } from "prosemirror-history" ;
9
9
import { undoInputRule } from "prosemirror-inputrules" ;
10
10
import { splitListItem } from "prosemirror-schema-list" ;
11
- import { atBlockStart } from "../lib/plugin-utils" ;
11
+ import { atBlockStart , inNode } from "../lib/plugin-utils" ;
12
12
13
13
const BACKSPACE_UNSET_NODES = [ "heading" , "code_block" ] ;
14
14
@@ -69,7 +69,31 @@ export function buildKeymap(
69
69
return true ;
70
70
} ) ;
71
71
72
- keys [ "Enter" ] = splitListItem ( schema . nodes . list_item ) ;
72
+ const doubleSpaceHardBreak = ( state , dispatch ) => {
73
+ const { $from } = state . selection ;
74
+ if ( $from . parent . type . spec . code || inNode ( state , schema . nodes . code_block ) ) {
75
+ return false ;
76
+ }
77
+
78
+ if ( $from . nodeBefore ?. text . endsWith ( " " ) ) {
79
+ if ( dispatch ) {
80
+ const tr = state . tr . replaceRangeWith (
81
+ $from . pos - 2 ,
82
+ $from . pos ,
83
+ schema . nodes . hard_break . create ( )
84
+ ) ;
85
+
86
+ dispatch ( tr . scrollIntoView ( ) ) ;
87
+ }
88
+ return true ;
89
+ }
90
+ return false ;
91
+ } ;
92
+
93
+ keys [ "Enter" ] = chainCommands (
94
+ doubleSpaceHardBreak ,
95
+ splitListItem ( schema . nodes . list_item )
96
+ ) ;
73
97
74
98
keys [ "Mod-Shift-_" ] = ( state , dispatch ) => {
75
99
dispatch ?. (
Original file line number Diff line number Diff line change @@ -600,6 +600,16 @@ def body(title)
600
600
expect ( rich ) . to have_css ( "hr" )
601
601
end
602
602
603
+ it "creates hard break when pressing Enter after double space at end of line" do
604
+ open_composer
605
+ composer . type_content ( "Line with double space " )
606
+ composer . send_keys ( :enter )
607
+ composer . type_content ( "Next line" )
608
+
609
+ composer . toggle_rich_editor
610
+ expect ( composer ) . to have_value ( "Line with double space\n Next line" )
611
+ end
612
+
603
613
it "supports Backspace to reset a heading" do
604
614
open_composer
605
615
composer . type_content ( "# With text" )
You can’t perform that action at this time.
0 commit comments