Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
frama-c
Commits
427756ac
Commit
427756ac
authored
1 year ago
by
Loïc Correnson
Browse files
Options
Downloads
Patches
Plain Diff
[dome/richtext] text buffer persistency
parent
a7c2d951
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ivette/src/dome/renderer/text/richtext.tsx
+83
-66
83 additions, 66 deletions
ivette/src/dome/renderer/text/richtext.tsx
with
83 additions
and
66 deletions
ivette/src/dome/renderer/text/richtext.tsx
+
83
−
66
View file @
427756ac
...
...
@@ -39,11 +39,93 @@ export function byDepth(a : Range, b : Range): number
}
/* -------------------------------------------------------------------------- */
/* ---
Code Mirror Utils
--- */
/* ---
Text Buffer
--- */
/* -------------------------------------------------------------------------- */
type
View
=
CM
.
EditorView
|
null
;
function
appendContents
(
view
:
CM
.
EditorView
,
text
:
string
):
void
{
const
length
=
view
.
state
.
doc
.
length
;
view
.
dispatch
({
changes
:
{
from
:
length
,
insert
:
text
}
});
}
function
dispatchContents
(
view
:
CM
.
EditorView
,
text
:
string
):
void
{
const
length
=
view
.
state
.
doc
.
length
;
view
.
dispatch
({
changes
:
{
from
:
0
,
to
:
length
,
insert
:
text
}
});
}
/**
Text contents of a RichText component.
This class can be used as a proxy to a the content of a {RichText}
component. Using the methods of the class, you can update or dump the
contents edited/viewed by the associated component.
At most one component shall be associated with a given Text buffer at the
same time.
All methods are bound to `this`.
*/
export
class
TextProxy
{
// --- Private part
private
buffer
=
''
;
private
proxy
:
View
=
null
;
constructor
()
{
this
.
clear
=
this
.
clear
.
bind
(
this
);
this
.
append
=
this
.
append
.
bind
(
this
);
this
.
toString
=
this
.
toString
.
bind
(
this
);
this
.
setContents
=
this
.
setContents
.
bind
(
this
);
this
.
connect
=
this
.
connect
.
bind
(
this
);
}
/** @ignore */
connect
(
newView
:
View
):
void
{
const
oldView
=
this
.
proxy
;
if
(
oldView
)
{
this
.
proxy
=
null
;
this
.
buffer
=
oldView
.
state
.
doc
.
toString
();
}
if
(
newView
)
{
dispatchContents
(
newView
,
this
.
buffer
);
this
.
proxy
=
newView
;
this
.
buffer
=
''
;
}
}
// --- Public part
clear
():
void
{
const
view
=
this
.
proxy
;
if
(
view
)
dispatchContents
(
view
,
''
);
else
this
.
buffer
=
''
;
}
toString
():
string
{
const
view
=
this
.
proxy
;
return
view
?
view
.
state
.
doc
.
toString
()
:
this
.
buffer
;
}
append
(
text
:
string
):
void
{
const
view
=
this
.
proxy
;
if
(
view
)
appendContents
(
view
,
text
);
else
this
.
buffer
+=
text
;
}
setContents
(
text
:
string
):
void
{
const
view
=
this
.
proxy
;
if
(
view
)
dispatchContents
(
view
,
text
);
else
this
.
buffer
=
text
;
}
}
/* -------------------------------------------------------------------------- */
/* --- Code Mirror Extensions --- */
/* -------------------------------------------------------------------------- */
class
Extension
{
readonly
extension
:
CS
.
Extension
[]
=
[];
pack
(
ext
:
CS
.
Extension
):
void
{
this
.
extension
.
push
(
ext
);
}
...
...
@@ -102,71 +184,6 @@ OnChange.pack(
}
));
/* -------------------------------------------------------------------------- */
/* --- Text Buffer --- */
/* -------------------------------------------------------------------------- */
/**
Text contents of a RichText component.
This class can be used as a proxy to a the content of a {RichText}
component. Using the methods of the class, you can update or dump the
contents edited/viewed by the associated component.
At most one component shall be associated with a given Text buffer at the
same time.
All methods are bound to `this`.
*/
export
class
TextProxy
{
// --- Private part
private
proxy
:
View
=
null
;
constructor
()
{
this
.
clear
=
this
.
clear
.
bind
(
this
);
this
.
append
=
this
.
append
.
bind
(
this
);
this
.
toString
=
this
.
toString
.
bind
(
this
);
this
.
setContents
=
this
.
setContents
.
bind
(
this
);
this
.
connect
=
this
.
connect
.
bind
(
this
);
}
/** @ignore */
connect
(
view
:
View
):
void
{
this
.
proxy
=
view
;
}
// --- Public part
clear
():
void
{
const
view
=
this
.
proxy
;
if
(
view
)
{
const
length
=
view
.
state
.
doc
.
length
;
view
.
dispatch
({
changes
:
{
from
:
0
,
to
:
length
,
insert
:
''
}
});
}
}
toString
():
string
{
return
this
.
proxy
?.
state
.
doc
.
toString
()
??
''
;
}
append
(
data
:
string
):
void
{
const
view
=
this
.
proxy
;
if
(
view
)
{
const
length
=
view
.
state
.
doc
.
length
;
view
?.
dispatch
({
changes
:
{
from
:
length
,
insert
:
data
}
});
}
}
setContents
(
data
:
string
):
void
{
const
view
=
this
.
proxy
;
if
(
view
)
{
const
length
=
view
.
state
.
doc
.
length
;
view
.
dispatch
({
changes
:
{
from
:
0
,
to
:
length
,
insert
:
data
}
});
}
}
}
/* -------------------------------------------------------------------------- */
/* --- Editor View --- */
/* -------------------------------------------------------------------------- */
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment