Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
godot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
community
godot
Commits
02f7908d
Unverified
Commit
02f7908d
authored
Jun 16, 2020
by
Rémi Verschelde
Committed by
GitHub
Jun 16, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #39598 from mrushyendra/replace_selection
Fix code editor Replace tool to work with 'Selection Only' option
parents
fa01e666
2be3a33c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
9 deletions
+36
-9
code_editor.cpp
editor/code_editor.cpp
+36
-9
No files found.
editor/code_editor.cpp
View file @
02f7908d
...
...
@@ -166,20 +166,47 @@ bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col)
}
void
FindReplaceBar
::
_replace
()
{
if
(
result_line
!=
-
1
&&
result_col
!=
-
1
)
{
text_edit
->
begin_complex_operation
();
bool
selection_enabled
=
text_edit
->
is_selection_active
();
Point2i
selection_begin
,
selection_end
;
if
(
selection_enabled
)
{
selection_begin
=
Point2i
(
text_edit
->
get_selection_from_line
(),
text_edit
->
get_selection_from_column
());
selection_end
=
Point2i
(
text_edit
->
get_selection_to_line
(),
text_edit
->
get_selection_to_column
());
}
text_edit
->
unfold_line
(
result_line
);
text_edit
->
select
(
result_line
,
result_col
,
result_line
,
result_col
+
get_search_text
().
length
());
text_edit
->
insert_text_at_cursor
(
get_replace_text
());
String
replace_text
=
get_replace_text
();
int
search_text_len
=
get_search_text
().
length
();
text_edit
->
end_complex_operation
();
text_edit
->
begin_complex_operation
();
if
(
selection_enabled
&&
is_selection_only
())
{
// To restrict search_current() to selected region
text_edit
->
cursor_set_line
(
selection_begin
.
width
);
text_edit
->
cursor_set_column
(
selection_begin
.
height
);
}
results_count
=
-
1
;
if
(
search_current
())
{
text_edit
->
unfold_line
(
result_line
);
text_edit
->
select
(
result_line
,
result_col
,
result_line
,
result_col
+
search_text_len
);
if
(
selection_enabled
&&
is_selection_only
())
{
Point2i
match_from
(
result_line
,
result_col
);
Point2i
match_to
(
result_line
,
result_col
+
search_text_len
);
if
(
!
(
match_from
<
selection_begin
||
match_to
>
selection_end
))
{
text_edit
->
insert_text_at_cursor
(
replace_text
);
if
(
match_to
.
x
==
selection_end
.
x
)
{
// Adjust selection bounds if necessary
selection_end
.
y
+=
replace_text
.
length
()
-
search_text_len
;
}
}
}
else
{
text_edit
->
insert_text_at_cursor
(
replace_text
);
}
}
text_edit
->
end_complex_operation
();
results_count
=
-
1
;
if
(
!
search_current
())
{
search_next
();
if
(
selection_enabled
&&
is_selection_only
())
{
// Reselect in order to keep 'Replace' restricted to selection
text_edit
->
select
(
selection_begin
.
x
,
selection_begin
.
y
,
selection_end
.
x
,
selection_end
.
y
);
}
else
{
text_edit
->
deselect
();
}
}
...
...
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