Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
e735be8b
Commit
e735be8b
authored
Apr 19, 2023
by
missionfloyd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Automatically select current word
parent
22bcc7be
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
5 deletions
+30
-5
javascript/edit-attention.js
javascript/edit-attention.js
+30
-5
No files found.
javascript/edit-attention.js
View file @
e735be8b
...
...
@@ -17,7 +17,7 @@ function keyupEditAttention(event){
// Find opening parenthesis around current cursor
const
before
=
text
.
substring
(
0
,
selectionStart
);
let
beforeParen
=
before
.
lastIndexOf
(
OPEN
);
if
(
beforeParen
==
-
1
)
return
false
;
if
(
beforeParen
==
-
1
)
return
false
;
let
beforeParenClose
=
before
.
lastIndexOf
(
CLOSE
);
while
(
beforeParenClose
!==
-
1
&&
beforeParenClose
>
beforeParen
)
{
beforeParen
=
before
.
lastIndexOf
(
OPEN
,
beforeParen
-
1
);
...
...
@@ -27,7 +27,7 @@ function keyupEditAttention(event){
// Find closing parenthesis around current cursor
const
after
=
text
.
substring
(
selectionStart
);
let
afterParen
=
after
.
indexOf
(
CLOSE
);
if
(
afterParen
==
-
1
)
return
false
;
if
(
afterParen
==
-
1
)
return
false
;
let
afterParenOpen
=
after
.
indexOf
(
OPEN
);
while
(
afterParenOpen
!==
-
1
&&
afterParen
>
afterParenOpen
)
{
afterParen
=
after
.
indexOf
(
CLOSE
,
afterParen
+
1
);
...
...
@@ -43,10 +43,35 @@ function keyupEditAttention(event){
target
.
setSelectionRange
(
selectionStart
,
selectionEnd
);
return
true
;
}
function
selectCurrentWord
(){
if
(
selectionStart
!==
selectionEnd
)
return
false
;
// Select the current word, find the start and end of the word (first space before and after)
const
wordStart
=
text
.
substring
(
0
,
selectionStart
).
lastIndexOf
(
"
"
)
+
1
;
const
wordEnd
=
text
.
substring
(
selectionEnd
).
indexOf
(
"
"
);
// If there is no space after the word, select to the end of the string
if
(
wordEnd
===
-
1
)
{
selectionEnd
=
text
.
length
;
}
else
{
selectionEnd
+=
wordEnd
;
}
selectionStart
=
wordStart
;
// Remove all punctuation at the end and beginning of the word
while
(
text
[
selectionStart
].
match
(
/
[
.,
\/
#!$%
\^
&
\*
;:{}=
\-
_`~()
]
/
))
{
selectionStart
++
;
}
while
(
text
[
selectionEnd
-
1
].
match
(
/
[
.,
\/
#!$%
\^
&
\*
;:{}=
\-
_`~()
]
/
))
{
selectionEnd
--
;
}
target
.
setSelectionRange
(
selectionStart
,
selectionEnd
);
return
true
;
}
// If the user hasn't selected anything, let's select their current parenthesis block
if
(
!
selectCurrentParenthesisBlock
(
'
<
'
,
'
>
'
))
{
selectCurrent
ParenthesisBlock
(
'
(
'
,
'
)
'
)
// If the user hasn't selected anything, let's select their current parenthesis block
or word
if
(
!
selectCurrentParenthesisBlock
(
'
<
'
,
'
>
'
)
&&
!
selectCurrentParenthesisBlock
(
'
(
'
,
'
)
'
))
{
selectCurrent
Word
();
}
event
.
preventDefault
();
...
...
Write
Preview
Markdown
is supported
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