1
1
use super :: * ;
2
2
use wasm_bindgen:: prelude:: * ;
3
+ use crate :: style:: * ;
3
4
4
5
impl Program {
5
6
pub fn new ( ) -> Program {
@@ -64,7 +65,7 @@ pub trait DocMutator {
64
65
unimplemented ! ( ) ;
65
66
}
66
67
67
- fn InsertDocString ( & mut self , _docstring : DocString ) {
68
+ fn InsertDocString ( & mut self , _docstring : DocString , _styles : OpaqueStyleMap ) {
68
69
unimplemented ! ( ) ;
69
70
}
70
71
@@ -105,7 +106,7 @@ impl DocMutator for NullDocMutator {
105
106
// no-op
106
107
}
107
108
108
- fn InsertDocString ( & mut self , _docstring : DocString ) {
109
+ fn InsertDocString ( & mut self , _docstring : DocString , _style : OpaqueStyleMap ) {
109
110
// no-op
110
111
}
111
112
@@ -129,7 +130,7 @@ pub enum Bytecode {
129
130
Exit ,
130
131
AdvanceElements ( usize ) ,
131
132
DeleteElements ( usize ) ,
132
- InsertDocString ( DocString ) ,
133
+ InsertDocString ( DocString , OpaqueStyleMap ) ,
133
134
WrapPrevious ( usize , Attrs ) ,
134
135
UnwrapSelf ,
135
136
JoinTextLeft ,
@@ -172,12 +173,14 @@ impl<'a> RecordingDocMutator<'a> {
172
173
// Partial string.
173
174
let partial = self . stepper . char_cursor_expect ( ) . right ( ) . expect ( "hey now" ) ;
174
175
// console_log!("🏟 {:?}", partial);
175
- self . bc . place ( Bytecode :: InsertDocString ( partial. clone ( ) ) ) ;
176
- unimplemented ! ( ) ;
177
- // FIXME this is broken
178
- // self.writer.place(&DocChars(partial.clone()));
179
- // self.stepper.next();
180
- // return true;
176
+ if let Some ( & DocChars ( ref text, ref styles) ) = self . stepper . head_raw ( ) {
177
+ self . bc . place ( Bytecode :: InsertDocString ( partial. clone ( ) , styles. clone ( ) ) ) ;
178
+ self . writer . place ( & DocChars ( partial. clone ( ) , styles. clone ( ) ) ) ;
179
+ } else {
180
+ unreachable ! ( ) ;
181
+ }
182
+ self . stepper . next ( ) ;
183
+ return true ;
181
184
} else if let ( Some ( ref previous) , Some ( ref head) ) =
182
185
( self . writer . past . last ( ) , self . stepper . head ( ) )
183
186
{
@@ -269,13 +272,12 @@ impl<'a> DocMutator for RecordingDocMutator<'a> {
269
272
}
270
273
}
271
274
272
- fn InsertDocString ( & mut self , docstring : DocString ) {
273
- self . bc . place ( Bytecode :: InsertDocString ( docstring. clone ( ) ) ) ;
275
+ fn InsertDocString ( & mut self , docstring : DocString , styles : OpaqueStyleMap ) {
276
+ self . bc . place ( Bytecode :: InsertDocString ( docstring. clone ( ) , styles . clone ( ) ) ) ;
274
277
275
278
// No-op stepper
276
279
277
- // FIXME
278
- // self.writer.place(&DocChars(docstring));
280
+ self . writer . place ( & DocChars ( docstring, styles) ) ;
279
281
}
280
282
281
283
fn UnwrapSelf ( & mut self ) {
@@ -320,7 +322,11 @@ impl<'a> DocMutator for RecordingDocMutator<'a> {
320
322
if let Some ( left) = cursor. left ( ) {
321
323
if left. char_len ( ) == count {
322
324
self . bc . place ( Bytecode :: DeleteElements ( 1 ) ) ; // It's over, delete time
323
- self . InsertDocString ( left. clone ( ) ) ; // Insert the left part of string
325
+ if let Some ( & DocChars ( _, ref styles) ) = self . stepper . head_raw ( ) {
326
+ self . InsertDocString ( left. clone ( ) , styles. to_owned ( ) ) ; // Insert the left part of string
327
+ } else {
328
+ unreachable ! ( ) ;
329
+ }
324
330
// The right part of the string is added WHEN
325
331
return ;
326
332
} else {
@@ -331,7 +337,11 @@ impl<'a> DocMutator for RecordingDocMutator<'a> {
331
337
text. seek_start_forward ( count) ;
332
338
}
333
339
// console_log!("\n\n\nPARTIAL ADVANEMENET {:?}\n\n\n", text);
334
- self . InsertDocString ( text) ;
340
+ if let Some ( & DocChars ( _, ref styles) ) = self . stepper . head_raw ( ) {
341
+ self . InsertDocString ( text, styles. clone ( ) ) ;
342
+ } else {
343
+ unreachable ! ( ) ;
344
+ }
335
345
}
336
346
}
337
347
}
0 commit comments