Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
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
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
MyCard
magicseteditor
Commits
188fbe73
Commit
188fbe73
authored
Mar 25, 2007
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correct cursor position for formating actions
parent
7ceb069c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
14 deletions
+20
-14
src/data/action/value.cpp
src/data/action/value.cpp
+16
-10
src/data/action/value.hpp
src/data/action/value.hpp
+1
-1
src/gui/value/text.cpp
src/gui/value/text.cpp
+3
-3
No files found.
src/data/action/value.cpp
View file @
188fbe73
...
...
@@ -96,26 +96,29 @@ TextValue& TextValueAction::value() const {
}
TextValueAction
*
toggle_format_action
(
const
TextValueP
&
value
,
const
String
&
tag
,
size_t
start
,
size_t
end
,
const
String
&
action_name
)
{
if
(
start
>
end
)
swap
(
start
,
end
);
TextValueAction
*
toggle_format_action
(
const
TextValueP
&
value
,
const
String
&
tag
,
size_t
start_i
,
size_t
end_i
,
size_t
start
,
size_t
end
,
const
String
&
action_name
)
{
if
(
start
>
end
)
{
swap
(
start
,
end
);
swap
(
start_i
,
end_i
);
}
String
new_value
;
const
String
&
str
=
value
->
value
();
// Are we inside the tag we are toggling?
size_t
tagpos
=
in_tag
(
str
,
_
(
"<"
)
+
tag
,
start
,
end
);
size_t
tagpos
=
in_tag
(
str
,
_
(
"<"
)
+
tag
,
start
_i
,
end_i
);
if
(
tagpos
==
String
::
npos
)
{
// we are not inside this tag, add it
new_value
=
str
.
substr
(
0
,
start
);
new_value
=
str
.
substr
(
0
,
start
_i
);
new_value
+=
_
(
"<"
)
+
tag
+
_
(
">"
);
new_value
+=
str
.
substr
(
start
,
end
-
start
);
new_value
+=
str
.
substr
(
start
_i
,
end_i
-
start_i
);
new_value
+=
_
(
"</"
)
+
tag
+
_
(
">"
);
new_value
+=
str
.
substr
(
end
);
new_value
+=
str
.
substr
(
end
_i
);
}
else
{
// we are inside this tag, _('remove') it
new_value
=
str
.
substr
(
0
,
start
);
new_value
=
str
.
substr
(
0
,
start
_i
);
new_value
+=
_
(
"</"
)
+
tag
+
_
(
">"
);
new_value
+=
str
.
substr
(
start
,
end
-
start
);
new_value
+=
str
.
substr
(
start
_i
,
end_i
-
start_i
);
new_value
+=
_
(
"<"
)
+
tag
+
_
(
">"
);
new_value
+=
str
.
substr
(
end
);
new_value
+=
str
.
substr
(
end
_i
);
}
// Build action
if
(
start
!=
end
)
{
...
...
@@ -132,7 +135,10 @@ TextValueAction* toggle_format_action(const TextValueP& value, const String& tag
TextValueAction
*
typing_action
(
const
TextValueP
&
value
,
size_t
start_i
,
size_t
end_i
,
size_t
start
,
size_t
end
,
const
String
&
replacement
,
const
String
&
action_name
)
{
bool
reverse
=
start
>
end
;
if
(
reverse
)
swap
(
start
,
end
);
if
(
reverse
)
{
swap
(
start
,
end
);
swap
(
start_i
,
end_i
);
}
String
new_value
=
tagged_substr_replace
(
value
->
value
(),
start_i
,
end_i
,
replacement
);
if
(
value
->
value
()
==
new_value
)
{
// no change
...
...
src/data/action/value.hpp
View file @
188fbe73
...
...
@@ -72,7 +72,7 @@ class TextValueAction : public ValueAction {
};
/// Action for toggleing some formating tag on or off in some range
TextValueAction
*
toggle_format_action
(
const
TextValueP
&
value
,
const
String
&
tag
,
size_t
start
,
size_t
end
,
const
String
&
action_name
);
TextValueAction
*
toggle_format_action
(
const
TextValueP
&
value
,
const
String
&
tag
,
size_t
start
_i
,
size_t
end_i
,
size_t
start
,
size_t
end
,
const
String
&
action_name
);
/// Typing in a TextValue, replace the selection [start...end) with replacement
/** start and end are cursor positions, start_i and end_i are indices*/
...
...
src/gui/value/text.cpp
View file @
188fbe73
...
...
@@ -390,15 +390,15 @@ void TextValueEditor::doFormat(int type) {
size_t
ss
=
selection_start
,
se
=
selection_end
;
switch
(
type
)
{
case
ID_FORMAT_BOLD
:
{
getSet
().
actions
.
add
(
toggle_format_action
(
valueP
(),
_
(
"b"
),
selection_start_i
,
selection_end_i
,
_
(
"Bold"
)));
getSet
().
actions
.
add
(
toggle_format_action
(
valueP
(),
_
(
"b"
),
selection_start_i
,
selection_end_i
,
selection_start
,
selection_end
,
_
(
"Bold"
)));
break
;
}
case
ID_FORMAT_ITALIC
:
{
getSet
().
actions
.
add
(
toggle_format_action
(
valueP
(),
_
(
"i"
),
selection_start_i
,
selection_end_i
,
_
(
"Italic"
)));
getSet
().
actions
.
add
(
toggle_format_action
(
valueP
(),
_
(
"i"
),
selection_start_i
,
selection_end_i
,
selection_start
,
selection_end
,
_
(
"Italic"
)));
break
;
}
case
ID_FORMAT_SYMBOL
:
{
getSet
().
actions
.
add
(
toggle_format_action
(
valueP
(),
_
(
"sym"
),
selection_start_i
,
selection_end_i
,
_
(
"Symbols"
)));
getSet
().
actions
.
add
(
toggle_format_action
(
valueP
(),
_
(
"sym"
),
selection_start_i
,
selection_end_i
,
selection_start
,
selection_end
,
_
(
"Symbols"
)));
break
;
}
}
...
...
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