iced_code_editor/canvas_editor/config.rs
1//! Builder-style configuration: context menu, theme/language, Vim toggle,
2//! wrap/whitespace/bracket/folding-enabled flags, auto-indent, auto-close
3//! brackets, indent style, search/replace enablement, and line numbers.
4
5use crate::canvas_editor::features::context_menu::ContextMenuEntry;
6use crate::canvas_editor::features::vim::VimMode;
7use crate::canvas_editor::{CodeEditor, IndentStyle};
8use crate::theme::Style;
9
10impl CodeEditor {
11 /// Replaces the custom context-menu entries.
12 pub fn set_custom_context_menu_entries(
13 &mut self,
14 entries: Vec<ContextMenuEntry>,
15 ) {
16 self.custom_context_menu_entries = entries;
17 }
18
19 /// Replaces the custom context-menu entries using the builder pattern.
20 #[must_use]
21 pub fn with_custom_context_menu_entries(
22 mut self,
23 entries: Vec<ContextMenuEntry>,
24 ) -> Self {
25 self.set_custom_context_menu_entries(entries);
26 self
27 }
28
29 /// Returns the custom context-menu entries in display order.
30 pub fn custom_context_menu_entries(&self) -> &[ContextMenuEntry] {
31 &self.custom_context_menu_entries
32 }
33
34 /// Sets whether the built-in editing actions appear in the context menu.
35 pub fn set_default_context_menu_enabled(&mut self, enabled: bool) {
36 self.default_context_menu_enabled = enabled;
37 }
38
39 /// Sets built-in context-menu visibility using the builder pattern.
40 #[must_use]
41 pub fn with_default_context_menu_enabled(mut self, enabled: bool) -> Self {
42 self.set_default_context_menu_enabled(enabled);
43 self
44 }
45
46 /// Returns whether the built-in context-menu actions are enabled.
47 pub fn default_context_menu_enabled(&self) -> bool {
48 self.default_context_menu_enabled
49 }
50
51 /// Sets whether the built-in reveal-in-file-manager action is shown.
52 pub fn set_reveal_in_file_manager_enabled(&mut self, enabled: bool) {
53 self.reveal_in_file_manager_enabled = enabled;
54 }
55
56 /// Sets reveal-in-file-manager visibility using the builder pattern.
57 #[must_use]
58 pub fn with_reveal_in_file_manager_enabled(
59 mut self,
60 enabled: bool,
61 ) -> Self {
62 self.set_reveal_in_file_manager_enabled(enabled);
63 self
64 }
65
66 /// Returns whether the reveal-in-file-manager action is shown.
67 pub fn reveal_in_file_manager_enabled(&self) -> bool {
68 self.reveal_in_file_manager_enabled
69 }
70
71 /// Enables or disables Vim behavior for this editor instance.
72 ///
73 /// Changing this setting enters a clean Normal mode without modifying the
74 /// buffer or command history.
75 pub fn set_vim_enabled(&mut self, enabled: bool) {
76 if self.is_grouping {
77 self.history.end_group();
78 self.is_grouping = false;
79 }
80 self.vim_enabled = enabled;
81 self.vim_state.enter_clean_normal_mode();
82 self.cursors.remove_all_but_primary();
83 let position = if enabled {
84 self.vim_normal_position(self.cursors.primary_position())
85 } else {
86 self.cursors.primary_position()
87 };
88 self.cursors.set_single(position);
89 self.is_dragging = false;
90 self.overlay_cache.clear();
91 }
92
93 /// Sets whether Vim behavior is enabled using the builder pattern.
94 #[must_use]
95 pub fn with_vim_enabled(mut self, enabled: bool) -> Self {
96 self.set_vim_enabled(enabled);
97 self
98 }
99
100 /// Returns whether Vim behavior is enabled for this editor instance.
101 pub fn vim_enabled(&self) -> bool {
102 self.vim_enabled
103 }
104
105 /// Returns the active Vim mode, or `None` when Vim behavior is disabled.
106 pub fn vim_mode(&self) -> Option<VimMode> {
107 self.vim_enabled.then(|| self.vim_state.mode())
108 }
109
110 /// Sets the theme style for the editor.
111 ///
112 /// # Arguments
113 ///
114 /// * `style` - The style to apply to the editor
115 ///
116 /// # Example
117 ///
118 /// ```
119 /// use iced_code_editor::{CodeEditor, theme};
120 ///
121 /// let mut editor = CodeEditor::new("fn main() {}", "rs");
122 /// editor.set_theme(theme::from_iced_theme(&iced::Theme::TokyoNightStorm));
123 /// ```
124 pub fn set_theme(&mut self, style: Style) {
125 self.style = style;
126 self.content_cache.clear();
127 self.overlay_cache.clear();
128 }
129
130 /// Sets the language for UI translations.
131 ///
132 /// This changes the language used for all UI text elements in the editor,
133 /// including search dialog tooltips, placeholders, and labels.
134 ///
135 /// # Arguments
136 ///
137 /// * `language` - The language to use for UI text
138 ///
139 /// # Example
140 ///
141 /// ```
142 /// use iced_code_editor::{CodeEditor, Language};
143 ///
144 /// let mut editor = CodeEditor::new("fn main() {}", "rs");
145 /// editor.set_language(Language::French);
146 /// ```
147 pub fn set_language(&mut self, language: crate::i18n::Language) {
148 self.translations.set_language(language);
149 self.overlay_cache.clear();
150 }
151
152 /// Returns the current UI language.
153 ///
154 /// # Returns
155 ///
156 /// The currently active language for UI text
157 ///
158 /// # Example
159 ///
160 /// ```
161 /// use iced_code_editor::{CodeEditor, Language};
162 ///
163 /// let editor = CodeEditor::new("fn main() {}", "rs");
164 /// let current_lang = editor.language();
165 /// ```
166 pub fn language(&self) -> crate::i18n::Language {
167 self.translations.language()
168 }
169
170 /// Sets whether line wrapping is enabled.
171 ///
172 /// When enabled, long lines will wrap at the viewport width or at a
173 /// configured column width.
174 ///
175 /// # Arguments
176 ///
177 /// * `enabled` - Whether to enable line wrapping
178 ///
179 /// # Example
180 ///
181 /// ```
182 /// use iced_code_editor::CodeEditor;
183 ///
184 /// let mut editor = CodeEditor::new("fn main() {}", "rs");
185 /// editor.set_wrap_enabled(false); // Disable wrapping
186 /// ```
187 pub fn set_wrap_enabled(&mut self, enabled: bool) {
188 if self.wrap_enabled != enabled {
189 self.wrap_enabled = enabled;
190 if enabled {
191 self.horizontal_scroll_offset = 0.0;
192 }
193 self.content_cache.clear();
194 self.overlay_cache.clear();
195 }
196 }
197
198 /// Returns whether line wrapping is enabled.
199 ///
200 /// # Returns
201 ///
202 /// `true` if line wrapping is enabled, `false` otherwise
203 pub fn wrap_enabled(&self) -> bool {
204 self.wrap_enabled
205 }
206
207 /// Enables or disables visible whitespace rendering.
208 ///
209 /// When enabled, space characters are rendered as `·` and tab characters
210 /// as `→`, both drawn in a dimmed color to remain non-intrusive. Toggling
211 /// this setting clears the content cache to trigger an immediate redraw.
212 ///
213 /// # Arguments
214 ///
215 /// * `enabled` - Whether to show whitespace characters
216 ///
217 /// # Example
218 ///
219 /// ```
220 /// use iced_code_editor::CodeEditor;
221 ///
222 /// let mut editor = CodeEditor::new("fn main() {}", "rs");
223 /// editor.set_show_whitespace(true);
224 /// ```
225 pub fn set_show_whitespace(&mut self, enabled: bool) {
226 if self.show_whitespace != enabled {
227 self.show_whitespace = enabled;
228 self.content_cache.clear();
229 }
230 }
231
232 /// Returns whether visible whitespace rendering is enabled.
233 pub fn show_whitespace(&self) -> bool {
234 self.show_whitespace
235 }
236
237 /// Enables or disables the matching-bracket/quote-pair highlight overlay.
238 ///
239 /// When enabled, placing the cursor next to a bracket (`(`, `)`, `[`,
240 /// `]`, `{`, `}`) or a quote (`"`, `'`) highlights it and its matching
241 /// pair. When disabled, no matching scan or highlight is performed.
242 ///
243 /// # Arguments
244 ///
245 /// * `enabled` - Whether to enable the bracket/quote-matching highlight
246 ///
247 /// # Example
248 ///
249 /// ```
250 /// use iced_code_editor::CodeEditor;
251 ///
252 /// let mut editor = CodeEditor::new("fn main() {}", "rs");
253 /// editor.set_bracket_match_highlight_enabled(false); // Disable
254 /// ```
255 pub fn set_bracket_match_highlight_enabled(&mut self, enabled: bool) {
256 if self.bracket_match_highlight_enabled != enabled {
257 self.bracket_match_highlight_enabled = enabled;
258 self.overlay_cache.clear();
259 }
260 }
261
262 /// Returns whether the matching-bracket/quote-pair highlight overlay is enabled.
263 pub fn bracket_match_highlight_enabled(&self) -> bool {
264 self.bracket_match_highlight_enabled
265 }
266
267 /// Enables or disables bracket-pair colorization (rainbow brackets).
268 ///
269 /// When enabled, each `( ) [ ] { }` is colored by its nesting depth, so a
270 /// matching pair always shares the same color, cycling through a fixed
271 /// palette as depth increases. When disabled, brackets render with their
272 /// normal syntax-highlight color.
273 ///
274 /// # Arguments
275 ///
276 /// * `enabled` - Whether to enable bracket-pair colorization
277 ///
278 /// # Example
279 ///
280 /// ```
281 /// use iced_code_editor::CodeEditor;
282 ///
283 /// let mut editor = CodeEditor::new("fn main() {}", "rs");
284 /// editor.set_bracket_pair_colorization_enabled(false); // Disable
285 /// ```
286 pub fn set_bracket_pair_colorization_enabled(&mut self, enabled: bool) {
287 if self.bracket_pair_colorization_enabled != enabled {
288 self.bracket_pair_colorization_enabled = enabled;
289 self.content_cache.clear();
290 }
291 }
292
293 /// Returns whether bracket-pair colorization (rainbow brackets) is enabled.
294 pub fn bracket_pair_colorization_enabled(&self) -> bool {
295 self.bracket_pair_colorization_enabled
296 }
297
298 /// Enables or disables code folding (collapse/expand blocks).
299 ///
300 /// When disabled, no fold chevrons are drawn and all lines are shown
301 /// regardless of the collapsed state (which is preserved, so re-enabling
302 /// restores the previously collapsed blocks).
303 ///
304 /// # Arguments
305 ///
306 /// * `enabled` - Whether to enable code folding
307 ///
308 /// # Example
309 ///
310 /// ```
311 /// use iced_code_editor::CodeEditor;
312 ///
313 /// let mut editor = CodeEditor::new("fn main() {}", "rs");
314 /// editor.set_folding_enabled(true);
315 /// ```
316 pub fn set_folding_enabled(&mut self, enabled: bool) {
317 if self.folding_enabled != enabled {
318 self.folding_enabled = enabled;
319 self.bump_fold_revision();
320 }
321 }
322
323 /// Returns whether code folding is enabled.
324 pub fn folding_enabled(&self) -> bool {
325 self.folding_enabled
326 }
327
328 /// Enables or disables automatic indentation on Enter.
329 ///
330 /// When enabled, pressing Enter copies the leading whitespace of the
331 /// current line to the new line. When disabled, the cursor is placed
332 /// at column 0 on the new line.
333 ///
334 /// # Arguments
335 ///
336 /// * `enabled` - `true` to enable auto-indentation, `false` to disable
337 pub fn set_auto_indent_enabled(&mut self, enabled: bool) {
338 self.auto_indent_enabled = enabled;
339 }
340
341 /// Returns whether auto-indentation is enabled.
342 ///
343 /// # Returns
344 ///
345 /// `true` if auto-indentation is enabled, `false` otherwise
346 pub fn auto_indent_enabled(&self) -> bool {
347 self.auto_indent_enabled
348 }
349
350 /// Enables or disables auto-closing of brackets and quotes.
351 ///
352 /// When enabled, typing an opening bracket/quote (`(`, `[`, `{`, `"`,
353 /// `'`) auto-inserts its matching closing character with the cursor
354 /// placed between them, typing the closing character right before an
355 /// already-inserted match moves the cursor past it instead of
356 /// duplicating it, and typing an opening bracket/quote while text is
357 /// selected wraps the selection in the pair instead of replacing it.
358 ///
359 /// # Arguments
360 ///
361 /// * `enabled` - `true` to enable auto-closing, `false` to disable
362 ///
363 /// # Example
364 ///
365 /// ```
366 /// use iced_code_editor::CodeEditor;
367 ///
368 /// let mut editor = CodeEditor::new("fn main() {}", "rs");
369 /// editor.set_auto_close_brackets(false); // Disable auto-closing
370 /// ```
371 pub fn set_auto_close_brackets(&mut self, enabled: bool) {
372 self.auto_close_brackets = enabled;
373 }
374
375 /// Returns whether auto-closing of brackets and quotes is enabled.
376 ///
377 /// # Returns
378 ///
379 /// `true` if auto-closing is enabled, `false` otherwise
380 pub fn auto_close_brackets(&self) -> bool {
381 self.auto_close_brackets
382 }
383
384 /// Sets the indentation style used when pressing the Tab key.
385 ///
386 /// # Arguments
387 ///
388 /// * `style` - The indentation style (`IndentStyle::Spaces(n)` or `IndentStyle::Tab`)
389 pub fn set_indent_style(&mut self, style: IndentStyle) {
390 self.indent_style = style;
391 }
392
393 /// Returns the current indentation style.
394 ///
395 /// # Returns
396 ///
397 /// The current [`IndentStyle`] configured for this editor
398 pub fn indent_style(&self) -> IndentStyle {
399 self.indent_style
400 }
401
402 /// Enables or disables the search/replace functionality.
403 ///
404 /// When disabled, search/replace keyboard shortcuts (Ctrl+F, Ctrl+H, F3)
405 /// will be ignored. If the search dialog is currently open, it will be closed.
406 ///
407 /// # Arguments
408 ///
409 /// * `enabled` - Whether to enable search/replace functionality
410 ///
411 /// # Example
412 ///
413 /// ```
414 /// use iced_code_editor::CodeEditor;
415 ///
416 /// let mut editor = CodeEditor::new("fn main() {}", "rs");
417 /// editor.set_search_replace_enabled(false); // Disable search/replace
418 /// ```
419 pub fn set_search_replace_enabled(&mut self, enabled: bool) {
420 self.search_replace_enabled = enabled;
421 if !enabled && self.search_state.is_open {
422 self.search_state.close();
423 }
424 }
425
426 /// Returns whether search/replace functionality is enabled.
427 ///
428 /// # Returns
429 ///
430 /// `true` if search/replace is enabled, `false` otherwise
431 pub fn search_replace_enabled(&self) -> bool {
432 self.search_replace_enabled
433 }
434
435 /// Returns the syntax highlighting language identifier for this editor.
436 ///
437 /// This is the language key passed at construction (e.g., `"lua"`, `"rs"`, `"py"`).
438 ///
439 /// # Examples
440 ///
441 /// ```
442 /// use iced_code_editor::CodeEditor;
443 /// let editor = CodeEditor::new("fn main() {}", "rs");
444 /// assert_eq!(editor.syntax(), "rs");
445 /// ```
446 pub fn syntax(&self) -> &str {
447 &self.syntax
448 }
449
450 /// Sets the line wrapping with builder pattern.
451 ///
452 /// # Arguments
453 ///
454 /// * `enabled` - Whether to enable line wrapping
455 ///
456 /// # Returns
457 ///
458 /// Self for method chaining
459 ///
460 /// # Example
461 ///
462 /// ```
463 /// use iced_code_editor::CodeEditor;
464 ///
465 /// let editor = CodeEditor::new("fn main() {}", "rs")
466 /// .with_wrap_enabled(false);
467 /// ```
468 #[must_use]
469 pub fn with_wrap_enabled(mut self, enabled: bool) -> Self {
470 self.wrap_enabled = enabled;
471 self
472 }
473
474 /// Enables or disables code folding using the builder pattern.
475 ///
476 /// # Arguments
477 ///
478 /// * `enabled` - Whether to enable code folding
479 ///
480 /// # Example
481 ///
482 /// ```
483 /// use iced_code_editor::CodeEditor;
484 ///
485 /// let editor = CodeEditor::new("fn main() {}", "rs")
486 /// .with_folding_enabled(true);
487 /// ```
488 #[must_use]
489 pub fn with_folding_enabled(mut self, enabled: bool) -> Self {
490 self.folding_enabled = enabled;
491 self
492 }
493
494 /// Sets the wrap column (fixed width wrapping).
495 ///
496 /// When set to `Some(n)`, lines will wrap at column `n`.
497 /// When set to `None`, lines will wrap at the viewport width.
498 ///
499 /// # Arguments
500 ///
501 /// * `column` - The column to wrap at, or None for viewport-based wrapping
502 ///
503 /// # Example
504 ///
505 /// ```
506 /// use iced_code_editor::CodeEditor;
507 ///
508 /// let editor = CodeEditor::new("fn main() {}", "rs")
509 /// .with_wrap_column(Some(80)); // Wrap at 80 characters
510 /// ```
511 #[must_use]
512 pub fn with_wrap_column(mut self, column: Option<usize>) -> Self {
513 self.wrap_column = column;
514 self
515 }
516
517 /// Sets whether line numbers are displayed.
518 ///
519 /// When disabled, the gutter is completely removed (0px width),
520 /// providing more space for code display.
521 ///
522 /// # Arguments
523 ///
524 /// * `enabled` - Whether to display line numbers
525 ///
526 /// # Example
527 ///
528 /// ```
529 /// use iced_code_editor::CodeEditor;
530 ///
531 /// let mut editor = CodeEditor::new("fn main() {}", "rs");
532 /// editor.set_line_numbers_enabled(false); // Hide line numbers
533 /// ```
534 pub fn set_line_numbers_enabled(&mut self, enabled: bool) {
535 if self.line_numbers_enabled != enabled {
536 self.line_numbers_enabled = enabled;
537 self.content_cache.clear();
538 self.overlay_cache.clear();
539 }
540 }
541
542 /// Returns whether line numbers are displayed.
543 ///
544 /// # Returns
545 ///
546 /// `true` if line numbers are displayed, `false` otherwise
547 pub fn line_numbers_enabled(&self) -> bool {
548 self.line_numbers_enabled
549 }
550
551 /// Sets the line numbers display with builder pattern.
552 ///
553 /// # Arguments
554 ///
555 /// * `enabled` - Whether to display line numbers
556 ///
557 /// # Returns
558 ///
559 /// Self for method chaining
560 ///
561 /// # Example
562 ///
563 /// ```
564 /// use iced_code_editor::CodeEditor;
565 ///
566 /// let editor = CodeEditor::new("fn main() {}", "rs")
567 /// .with_line_numbers_enabled(false);
568 /// ```
569 #[must_use]
570 pub fn with_line_numbers_enabled(mut self, enabled: bool) -> Self {
571 self.line_numbers_enabled = enabled;
572 self
573 }
574}
575
576#[cfg(test)]
577mod tests {
578 use super::*;
579 use crate::canvas_editor::features::context_menu::ContextMenuItem;
580 use crate::canvas_editor::features::vim;
581
582 #[test]
583 fn test_custom_context_menu_configuration() {
584 let custom_entries = vec![
585 ContextMenuEntry::item("format", "Format document")
586 .with_shortcut("Shift+Alt+F"),
587 ContextMenuEntry::separator(),
588 ContextMenuEntry::Item(
589 ContextMenuItem::new("rename", "Rename symbol")
590 .with_enabled(false),
591 ),
592 ];
593
594 let editor = CodeEditor::new("", "rs")
595 .with_custom_context_menu_entries(custom_entries.clone())
596 .with_default_context_menu_enabled(false);
597
598 assert_eq!(editor.custom_context_menu_entries(), custom_entries);
599 assert!(!editor.default_context_menu_enabled());
600
601 let default_editor = CodeEditor::new("", "rs");
602 assert!(default_editor.custom_context_menu_entries().is_empty());
603 assert!(default_editor.default_context_menu_enabled());
604 }
605
606 #[test]
607 fn test_reveal_in_file_manager_configuration() {
608 let mut editor = CodeEditor::new("", "rs");
609 assert!(!editor.reveal_in_file_manager_enabled());
610
611 editor.set_reveal_in_file_manager_enabled(true);
612 assert!(editor.reveal_in_file_manager_enabled());
613
614 let editor =
615 CodeEditor::new("", "rs").with_reveal_in_file_manager_enabled(true);
616 assert!(editor.reveal_in_file_manager_enabled());
617 }
618
619 #[test]
620 fn test_auto_close_brackets_configuration() {
621 let mut editor = CodeEditor::new("", "rs");
622 assert!(editor.auto_close_brackets());
623
624 editor.set_auto_close_brackets(false);
625 assert!(!editor.auto_close_brackets());
626
627 editor.set_auto_close_brackets(true);
628 assert!(editor.auto_close_brackets());
629 }
630
631 #[test]
632 fn test_bracket_match_highlight_configuration() {
633 let mut editor = CodeEditor::new("", "rs");
634 assert!(editor.bracket_match_highlight_enabled());
635
636 editor.set_bracket_match_highlight_enabled(false);
637 assert!(!editor.bracket_match_highlight_enabled());
638
639 editor.set_bracket_match_highlight_enabled(true);
640 assert!(editor.bracket_match_highlight_enabled());
641 }
642
643 #[test]
644 fn test_bracket_pair_colorization_configuration() {
645 let mut editor = CodeEditor::new("", "rs");
646 assert!(editor.bracket_pair_colorization_enabled());
647
648 editor.set_bracket_pair_colorization_enabled(false);
649 assert!(!editor.bracket_pair_colorization_enabled());
650
651 editor.set_bracket_pair_colorization_enabled(true);
652 assert!(editor.bracket_pair_colorization_enabled());
653 }
654
655 #[test]
656 fn vim_disabled_by_default() {
657 let editor = CodeEditor::new("unchanged", "rs");
658
659 assert!(!editor.vim_enabled());
660 assert_eq!(editor.vim_mode(), None);
661 assert_eq!(editor.content(), "unchanged");
662 assert!(!editor.can_undo());
663 assert!(!editor.can_redo());
664 }
665
666 #[test]
667 fn vim_enable_enters_clean_normal_mode() {
668 let mut editor = CodeEditor::new("unchanged", "rs");
669 assert_eq!(editor.vim_state.parse_key('9'), None);
670 assert_eq!(editor.vim_state.parse_key('d'), None);
671
672 editor.set_vim_enabled(true);
673
674 assert!(editor.vim_enabled());
675 assert_eq!(editor.vim_mode(), Some(VimMode::Normal));
676 assert_eq!(
677 editor.vim_state.parse_key('l'),
678 Some(vim::VimAction::Motion {
679 motion: vim::VimMotion::Right,
680 count: 1,
681 explicit_count: false,
682 })
683 );
684 assert_eq!(editor.content(), "unchanged");
685 assert!(!editor.can_undo());
686 assert!(!editor.can_redo());
687 }
688
689 #[test]
690 fn vim_disable_clears_pending_state() {
691 let mut editor =
692 CodeEditor::new("unchanged", "rs").with_vim_enabled(true);
693 assert_eq!(editor.vim_state.parse_key('4'), None);
694 assert_eq!(editor.vim_state.parse_key('d'), None);
695
696 editor.set_vim_enabled(false);
697 assert!(!editor.vim_enabled());
698 assert_eq!(editor.vim_mode(), None);
699
700 editor.set_vim_enabled(true);
701 assert_eq!(
702 editor.vim_state.parse_key('w'),
703 Some(vim::VimAction::Motion {
704 motion: vim::VimMotion::WordForward,
705 count: 1,
706 explicit_count: false,
707 })
708 );
709 assert_eq!(editor.content(), "unchanged");
710 assert!(!editor.can_undo());
711 assert!(!editor.can_redo());
712 }
713
714 #[test]
715 fn vim_reset_clears_pending_state() {
716 let mut editor = CodeEditor::new("before", "rs").with_vim_enabled(true);
717 assert_eq!(editor.vim_state.parse_key('3'), None);
718 assert_eq!(editor.vim_state.parse_key('g'), None);
719
720 let _ = editor.reset("after");
721
722 assert_eq!(editor.vim_mode(), Some(VimMode::Normal));
723 assert_eq!(editor.vim_state.parse_key('g'), None);
724 assert_eq!(
725 editor.vim_state.parse_key('g'),
726 Some(vim::VimAction::Motion {
727 motion: vim::VimMotion::DocumentStart,
728 count: 1,
729 explicit_count: false,
730 })
731 );
732 assert_eq!(editor.content(), "after");
733 assert!(!editor.can_undo());
734 assert!(!editor.can_redo());
735 }
736
737 #[test]
738 fn test_syntax_getter() {
739 let editor = CodeEditor::new("", "lua");
740 assert_eq!(editor.syntax(), "lua");
741 }
742
743 #[test]
744 fn test_folding_enabled_by_default() {
745 let editor = CodeEditor::new("fn main() {}", "rs");
746 assert!(editor.folding_enabled());
747 }
748}