Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
GuiΩ
ActivitesMentales_Django
Commits
555b23be
Commit
555b23be
authored
Jun 17, 2022
by
GuiΩ
Browse files
fix(CodeEditor): deal correctly with Tab and Enter after last char
parent
c0308658
Changes
1
Hide whitespace changes
Inline
Side-by-side
frontend/src/components/CodeEditor.vue
View file @
555b23be
...
...
@@ -11,7 +11,6 @@
-->
<
script
lang=
"ts"
setup
>
interface
ICodeEditorProps
{
code
?:
string
,
tabsize
?:
number
...
...
@@ -19,10 +18,10 @@
const
emit
=
defineEmits
([
'
input
'
,
'
update:code
'
])
const
props
:
ICodeEditorProps
=
defineProps
<
{
code
?
:
''
,
tabsize
?
:
2
}
>
(
)
const
props
=
withDefaults
(
defineProps
<
ICodeEditorProps
>
(),
{
code
:
''
,
tabsize
:
2
})
function
handleInput
(
event
:
InputEvent
)
{
const
textarea
=
event
.
target
as
HTMLInputElement
...
...
@@ -49,11 +48,12 @@
if
(
start
===
end
&&
textarea
.
value
.
charAt
(
start
)
===
"
\n
"
)
{
textarea
.
selectionEnd
=
start
+
textarea
.
value
.
substring
(
start
+
1
).
search
(
/
[^
]
/
);
}
break
;
break
case
'
Enter
'
:
event
.
preventDefault
();
let
spaces
=
"
\n
"
+
"
"
.
repeat
(
lineIndentSize
);
let
nextCharIndex
=
end
+
textarea
.
value
.
substring
(
end
).
search
(
/
[^
]
/
)
let
nextNotSpace
=
textarea
.
value
.
substring
(
end
).
search
(
/
[^
]
/
)
let
nextCharIndex
=
end
+
(
nextNotSpace
>
-
1
?
nextNotSpace
:
0
)
if
(
start
<=
lineStart
+
lineIndentSize
)
{
// cursor before the first non empty char
end
=
lineStart
+
lineIndentSize
+
end
-
start
+
1
;
start
=
lineStart
+
lineIndentSize
+
1
;
...
...
@@ -64,7 +64,7 @@
textarea
.
selectionStart
=
start
+
lineIndentSize
+
1
;
textarea
.
selectionEnd
=
textarea
.
selectionStart
;
emit
(
'
input
'
,
textarea
.
value
);
break
;
break
case
'
Tab
'
:
event
.
preventDefault
();
let
nbspaces
=
props
.
tabsize
!
;
...
...
@@ -94,7 +94,7 @@
textarea
.
selectionEnd
=
textarea
.
selectionStart
;
}
emit
(
'
input
'
,
textarea
.
value
);
break
;
break
}
}
</
script
>
...
...
@@ -106,8 +106,7 @@ textarea(
rows="30"
spellcheck="false"
@keydown="handleKeyDown"
@input="handleInput"
)
@input="handleInput")/
</
template
>
<
style
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment