@@ -571,30 +571,27 @@ function OrgMappings:org_return()
571
571
end
572
572
end
573
573
574
- local old_mapping = vim .b .org_old_cr_mapping
575
-
574
+ local global_cr_keymap = utils .get_keymap ({
575
+ mode = ' i' ,
576
+ lhs = ' <CR>' ,
577
+ })
576
578
-- No other mapping for <CR>, just reproduce it.
577
- if not old_mapping or vim .tbl_isempty (old_mapping ) then
579
+ if not global_cr_keymap or vim .tbl_isempty (global_cr_keymap ) then
578
580
return vim .api .nvim_feedkeys (utils .esc (' <CR>' ), ' n' , true )
579
581
end
580
582
581
- local rhs = old_mapping .rhs
582
- local eval = old_mapping .expr > 0
583
+ local rhs = global_cr_keymap .rhs
583
584
584
- if old_mapping .callback then
585
- rhs = old_mapping .callback ()
586
- eval = false
585
+ if global_cr_keymap .callback then
586
+ rhs = global_cr_keymap .callback ()
587
587
end
588
588
589
- if eval then
589
+ -- If mapping contains `\r`, it means it's already escaped and evaluated
590
+ if global_cr_keymap .expr > 0 and not rhs :lower ():find (' \r ' ) then
591
+ rhs = vim .api .nvim_replace_termcodes (rhs , true , true , true )
590
592
rhs = vim .api .nvim_eval (rhs )
591
593
end
592
594
593
- -- If the rhs is empty, assume that callback already handled the action
594
- if old_mapping .callback and not rhs then
595
- return
596
- end
597
-
598
595
return vim .api .nvim_feedkeys (rhs , ' n' , true )
599
596
end
600
597
0 commit comments