1use std::path::Path;
15use std::sync::Arc;
16
17use rust_i18n::t;
18
19use crate::model::event::BufferId;
20use crate::state::EditorState;
21
22use super::Editor;
23
24impl Editor {
25 pub fn open_file(&mut self, path: &Path) -> anyhow::Result<BufferId> {
30 self.active_window_mut()
40 .redirect_active_split_away_from_dock_if_needed();
41
42 let active_had_path = self
46 .buffers()
47 .get(&self.active_buffer())
48 .and_then(|s| s.buffer.file_path())
49 .is_some();
50
51 let buffer_id = self.open_file_no_focus(path)?;
52
53 let is_new_buffer = self.active_buffer() != buffer_id;
57
58 if is_new_buffer && !self.active_window().suppress_position_history_once {
59 self.active_window_mut()
61 .position_history
62 .commit_pending_movement();
63
64 let cursors = self.active_cursors();
66 let position = cursors.primary().position;
67 let anchor = cursors.primary().anchor;
68 let active_buffer_id = self.active_buffer();
69 let ph = &mut self.active_window_mut().position_history;
70 ph.record_movement(active_buffer_id, position, anchor);
71 ph.commit_pending_movement();
72 }
73
74 self.set_active_buffer(buffer_id);
75
76 if !is_new_buffer && !active_had_path {
83 #[cfg(feature = "plugins")]
84 self.update_plugin_state_snapshot();
85
86 self.plugin_manager.read().unwrap().run_hook(
87 "buffer_activated",
88 crate::services::plugins::hooks::HookArgs::BufferActivated { buffer_id },
89 );
90 }
91
92 let display_name = self
94 .active_window()
95 .buffer_metadata
96 .get(&buffer_id)
97 .map(|m| m.display_name.clone())
98 .unwrap_or_else(|| path.display().to_string());
99
100 let is_binary = self
102 .buffers()
103 .get(&buffer_id)
104 .map(|s| s.buffer.is_binary())
105 .unwrap_or(false);
106
107 if is_binary {
109 self.active_window_mut().status_message =
110 Some(t!("buffer.opened_binary", name = display_name).to_string());
111 } else {
112 self.active_window_mut().status_message =
113 Some(t!("buffer.opened", name = display_name).to_string());
114 }
115
116 Ok(buffer_id)
117 }
118
119 pub fn open_file_no_focus(&mut self, path: &Path) -> anyhow::Result<BufferId> {
139 self.open_file_no_focus_inner(path, true)
140 }
141
142 pub(super) fn open_file_for_preview(&mut self, path: &Path) -> anyhow::Result<BufferId> {
154 self.open_file_no_focus_inner(path, false)
155 }
156
157 fn open_file_no_focus_inner(
158 &mut self,
159 path: &Path,
160 allow_replace_empty: bool,
161 ) -> anyhow::Result<BufferId> {
162 if !self.authority.filesystem.is_remote_connected() {
165 anyhow::bail!(
166 "Cannot open file: remote connection lost ({})",
167 self.authority
168 .filesystem
169 .remote_connection_info()
170 .unwrap_or("unknown host")
171 );
172 }
173
174 let base_dir = if self.authority.filesystem.remote_connection_info().is_some() {
177 self.authority
178 .filesystem
179 .home_dir()
180 .unwrap_or_else(|_| self.working_dir.clone())
181 } else {
182 self.working_dir.clone()
183 };
184
185 let resolved_path = if path.is_relative() {
186 base_dir.join(path)
187 } else {
188 path.to_path_buf()
189 };
190
191 let file_exists = self.authority.filesystem.exists(&resolved_path);
194
195 let display_path = resolved_path.clone();
199
200 let canonical_path = if file_exists {
204 self.authority
205 .filesystem
206 .canonicalize(&resolved_path)
207 .unwrap_or_else(|_| resolved_path.clone())
208 } else {
209 if let Some(parent) = resolved_path.parent() {
211 let canonical_parent = if parent.as_os_str().is_empty() {
212 base_dir.clone()
214 } else {
215 self.authority
216 .filesystem
217 .canonicalize(parent)
218 .unwrap_or_else(|_| parent.to_path_buf())
219 };
220 if let Some(filename) = resolved_path.file_name() {
221 canonical_parent.join(filename)
222 } else {
223 resolved_path
224 }
225 } else {
226 resolved_path
227 }
228 };
229 let path = canonical_path.as_path();
230
231 if self.authority.filesystem.is_dir(path).unwrap_or(false) {
235 anyhow::bail!(t!("buffer.cannot_open_directory"));
236 }
237
238 let already_open = self
240 .buffers()
241 .iter()
242 .find(|(_, state)| state.buffer.file_path() == Some(path))
243 .map(|(id, _)| *id);
244
245 if let Some(id) = already_open {
246 return Ok(id);
247 }
248
249 let replace_current = allow_replace_empty && {
254 let current_state = self
255 .windows
256 .get(&self.active_window)
257 .map(|w| &w.buffers)
258 .expect("active window present")
259 .get(&self.active_buffer())
260 .unwrap();
261 !current_state.is_composite_buffer
262 && current_state.buffer.is_empty()
263 && !current_state.buffer.is_modified()
264 && current_state.buffer.file_path().is_none()
265 };
266
267 let buffer_id = if replace_current {
268 self.active_buffer()
270 } else {
271 let id = self.alloc_buffer_id();
273 id
274 };
275
276 tracing::info!(
278 "[SYNTAX DEBUG] open_file_no_focus: path={:?}, extension={:?}, catalog={}",
279 path,
280 path.extension(),
281 self.grammar_registry.catalog().len(),
282 );
283 let mut state = if file_exists {
284 let buffer = crate::model::buffer::Buffer::load_from_file(
287 &canonical_path,
288 self.config.editor.large_file_threshold_bytes as usize,
289 Arc::clone(&self.authority.filesystem),
290 )?;
291 let first_line = buffer.first_line_lossy();
292 let detected =
293 crate::primitives::detected_language::DetectedLanguage::from_path_with_fallback(
294 &display_path,
295 first_line.as_deref(),
296 &self.grammar_registry,
297 &self.config.languages,
298 self.config.default_language.as_deref(),
299 );
300 EditorState::from_buffer_with_language(buffer, detected)
301 } else {
302 EditorState::new_with_path(
304 self.config.editor.large_file_threshold_bytes as usize,
305 Arc::clone(&self.authority.filesystem),
306 path.to_path_buf(),
307 )
308 };
309 let is_binary = state.buffer.is_binary();
313 if is_binary {
314 state.editing_disabled = true;
316 tracing::info!("Detected binary file: {}", path.display());
317 }
318
319 let mut whitespace =
323 crate::config::WhitespaceVisibility::from_editor_config(&self.config.editor);
324 state.buffer_settings.auto_close = self.config.editor.auto_close;
325 state.buffer_settings.auto_surround = self.config.editor.auto_surround;
326 if let Some(lang_config) = self.config.languages.get(&state.language) {
327 whitespace = whitespace.with_language_tab_override(lang_config.show_whitespace_tabs);
328 state.buffer_settings.use_tabs =
329 lang_config.use_tabs.unwrap_or(self.config.editor.use_tabs);
330 state.buffer_settings.tab_size =
332 lang_config.tab_size.unwrap_or(self.config.editor.tab_size);
333 if state.buffer_settings.auto_close {
335 if let Some(lang_auto_close) = lang_config.auto_close {
336 state.buffer_settings.auto_close = lang_auto_close;
337 }
338 }
339 if state.buffer_settings.auto_surround {
341 if let Some(lang_auto_surround) = lang_config.auto_surround {
342 state.buffer_settings.auto_surround = lang_auto_surround;
343 }
344 }
345 } else {
346 state.buffer_settings.tab_size = self.config.editor.tab_size;
347 state.buffer_settings.use_tabs = self.config.editor.use_tabs;
348 }
349 state.buffer_settings.whitespace = whitespace;
350
351 state
353 .margins
354 .configure_for_line_numbers(self.config.editor.line_numbers);
355
356 self.windows
357 .get_mut(&self.active_window)
358 .map(|w| &mut w.buffers)
359 .expect("active window present")
360 .insert(buffer_id, state);
361 self.active_window_mut()
362 .event_logs
363 .insert(buffer_id, crate::model::event::EventLog::new());
364
365 let mut metadata = super::types::BufferMetadata::with_file(
367 path.to_path_buf(),
368 &display_path,
369 &self.working_dir,
370 self.authority.path_translation.as_ref(),
371 );
372
373 if is_binary {
375 metadata.binary = true;
376 metadata.read_only = true;
377 metadata.disable_lsp(t!("buffer.binary_file").to_string());
378 }
379
380 if file_exists && !metadata.read_only && !self.authority.filesystem.is_writable(path) {
382 metadata.read_only = true;
383 }
384
385 if metadata.read_only {
387 if let Some(state) = self
388 .windows
389 .get_mut(&self.active_window)
390 .map(|w| &mut w.buffers)
391 .expect("active window present")
392 .get_mut(&buffer_id)
393 {
394 state.editing_disabled = true;
395 }
396 }
397
398 if !is_binary {
400 self.notify_lsp_file_opened(path, buffer_id, &mut metadata);
401 }
402
403 self.active_window_mut()
405 .buffer_metadata
406 .insert(buffer_id, metadata);
407
408 let target_split = self.active_window().preferred_split_for_file();
411 let line_wrap = self.active_window().resolve_line_wrap_for_buffer(buffer_id);
412 let wrap_column = self
413 .active_window()
414 .resolve_wrap_column_for_buffer(buffer_id);
415 let page_view = self.active_window().resolve_page_view_for_buffer(buffer_id);
416 if let Some(view_state) = self
417 .windows
418 .get_mut(&self.active_window)
419 .and_then(|w| w.split_view_states_mut())
420 .expect("active window must have a populated split layout")
421 .get_mut(&target_split)
422 {
423 view_state.add_buffer(buffer_id);
424 let buf_state = view_state.ensure_buffer_state(buffer_id);
426 buf_state.apply_config_defaults(
427 self.config.editor.line_numbers,
428 self.config.editor.highlight_current_line,
429 line_wrap,
430 self.config.editor.wrap_indent,
431 wrap_column,
432 self.config.editor.rulers.clone(),
433 );
434 if let Some(page_width) = page_view {
436 buf_state.activate_page_view(page_width);
437 }
438 }
439
440 self.active_window_mut()
443 .restore_global_file_state(buffer_id, path, target_split);
444
445 self.emit_event(
447 crate::model::control_event::events::FILE_OPENED.name,
448 serde_json::json!({
449 "path": path.display().to_string(),
450 "buffer_id": buffer_id.0
451 }),
452 );
453
454 self.watch_file(path);
456
457 self.plugin_manager.read().unwrap().run_hook(
459 "after_file_open",
460 crate::services::plugins::hooks::HookArgs::AfterFileOpen {
461 buffer_id,
462 path: path.to_path_buf(),
463 },
464 );
465
466 Ok(buffer_id)
467 }
468
469 pub fn open_file_with_encoding(
477 &mut self,
478 path: &Path,
479 encoding: crate::model::buffer::Encoding,
480 ) -> anyhow::Result<BufferId> {
481 let base_dir = self.working_dir.clone();
483
484 let resolved_path = if path.is_relative() {
485 base_dir.join(path)
486 } else {
487 path.to_path_buf()
488 };
489
490 let display_path = resolved_path.clone();
492
493 let canonical_path = self
495 .authority
496 .filesystem
497 .canonicalize(&resolved_path)
498 .unwrap_or_else(|_| resolved_path.clone());
499 let path = canonical_path.as_path();
500
501 let already_open = self
503 .buffers()
504 .iter()
505 .find(|(_, state)| state.buffer.file_path() == Some(path))
506 .map(|(id, _)| *id);
507
508 if let Some(id) = already_open {
509 if let Some(state) = self
511 .windows
512 .get_mut(&self.active_window)
513 .map(|w| &mut w.buffers)
514 .expect("active window present")
515 .get_mut(&id)
516 {
517 state.buffer.set_encoding(encoding);
518 }
519 self.set_active_buffer(id);
520 return Ok(id);
521 }
522
523 let buffer_id = self.alloc_buffer_id();
525
526 let buffer = crate::model::buffer::Buffer::load_from_file_with_encoding(
528 path,
529 encoding,
530 Arc::clone(&self.authority.filesystem),
531 crate::model::buffer::BufferConfig {
532 estimated_line_length: self.config.editor.estimated_line_length,
533 },
534 )?;
535 let first_line = buffer.first_line_lossy();
536 let detected =
539 crate::primitives::detected_language::DetectedLanguage::from_path_with_fallback(
540 &display_path,
541 first_line.as_deref(),
542 &self.grammar_registry,
543 &self.config.languages,
544 self.config.default_language.as_deref(),
545 );
546
547 let mut state = EditorState::from_buffer_with_language(buffer, detected);
548
549 state
550 .margins
551 .configure_for_line_numbers(self.config.editor.line_numbers);
552
553 self.windows
554 .get_mut(&self.active_window)
555 .map(|w| &mut w.buffers)
556 .expect("active window present")
557 .insert(buffer_id, state);
558 self.active_window_mut()
559 .event_logs
560 .insert(buffer_id, crate::model::event::EventLog::new());
561
562 let metadata = super::types::BufferMetadata::with_file(
563 path.to_path_buf(),
564 &display_path,
565 &self.working_dir,
566 self.authority.path_translation.as_ref(),
567 );
568 self.active_window_mut()
569 .buffer_metadata
570 .insert(buffer_id, metadata);
571
572 let target_split = self.active_window().preferred_split_for_file();
574 let line_wrap = self.active_window().resolve_line_wrap_for_buffer(buffer_id);
575 let wrap_column = self
576 .active_window()
577 .resolve_wrap_column_for_buffer(buffer_id);
578 if let Some(view_state) = self
579 .windows
580 .get_mut(&self.active_window)
581 .and_then(|w| w.split_view_states_mut())
582 .expect("active window must have a populated split layout")
583 .get_mut(&target_split)
584 {
585 view_state.add_buffer(buffer_id);
586 let buf_state = view_state.ensure_buffer_state(buffer_id);
587 buf_state.apply_config_defaults(
588 self.config.editor.line_numbers,
589 self.config.editor.highlight_current_line,
590 line_wrap,
591 self.config.editor.wrap_indent,
592 wrap_column,
593 self.config.editor.rulers.clone(),
594 );
595 }
596
597 self.set_active_buffer(buffer_id);
598
599 Ok(buffer_id)
600 }
601
602 pub fn reload_with_encoding(
606 &mut self,
607 encoding: crate::model::buffer::Encoding,
608 ) -> anyhow::Result<()> {
609 let buffer_id = self.active_buffer();
610
611 let path = self
613 .buffers()
614 .get(&buffer_id)
615 .and_then(|s| s.buffer.file_path().map(|p| p.to_path_buf()))
616 .ok_or_else(|| anyhow::anyhow!("Buffer has no file path"))?;
617
618 if let Some(state) = self
620 .windows
621 .get(&self.active_window)
622 .map(|w| &w.buffers)
623 .expect("active window present")
624 .get(&buffer_id)
625 {
626 if state.buffer.is_modified() {
627 anyhow::bail!("Cannot reload: buffer has unsaved modifications");
628 }
629 }
630
631 let new_buffer = crate::model::buffer::Buffer::load_from_file_with_encoding(
633 &path,
634 encoding,
635 Arc::clone(&self.authority.filesystem),
636 crate::model::buffer::BufferConfig {
637 estimated_line_length: self.config.editor.estimated_line_length,
638 },
639 )?;
640
641 if let Some(state) = self
643 .windows
644 .get_mut(&self.active_window)
645 .map(|w| &mut w.buffers)
646 .expect("active window present")
647 .get_mut(&buffer_id)
648 {
649 state.buffer = new_buffer;
650 state.highlighter.invalidate_all();
652 }
653
654 let split_id = self
656 .windows
657 .get(&self.active_window)
658 .and_then(|w| w.buffers.splits())
659 .map(|(mgr, _)| mgr)
660 .expect("active window must have a populated split layout")
661 .active_split();
662 if let Some(view_state) = self
663 .windows
664 .get_mut(&self.active_window)
665 .and_then(|w| w.split_view_states_mut())
666 .expect("active window must have a populated split layout")
667 .get_mut(&split_id)
668 {
669 if let Some(buf_state) = view_state.keyed_states.get_mut(&buffer_id) {
670 buf_state.cursors = crate::model::cursor::Cursors::new();
671 }
672 }
673
674 Ok(())
675 }
676
677 pub fn open_file_large_encoding_confirmed(&mut self, path: &Path) -> anyhow::Result<BufferId> {
682 let base_dir = self.working_dir.clone();
684
685 let resolved_path = if path.is_relative() {
686 base_dir.join(path)
687 } else {
688 path.to_path_buf()
689 };
690
691 let display_path = resolved_path.clone();
693
694 let canonical_path = self
696 .authority
697 .filesystem
698 .canonicalize(&resolved_path)
699 .unwrap_or_else(|_| resolved_path.clone());
700 let path = canonical_path.as_path();
701
702 let already_open = self
704 .buffers()
705 .iter()
706 .find(|(_, state)| state.buffer.file_path() == Some(path))
707 .map(|(id, _)| *id);
708
709 if let Some(id) = already_open {
710 self.set_active_buffer(id);
711 return Ok(id);
712 }
713
714 let buffer_id = self.alloc_buffer_id();
716
717 let buffer = crate::model::buffer::Buffer::load_large_file_confirmed(
719 path,
720 Arc::clone(&self.authority.filesystem),
721 )?;
722 let first_line = buffer.first_line_lossy();
723 let detected =
726 crate::primitives::detected_language::DetectedLanguage::from_path_with_fallback(
727 &display_path,
728 first_line.as_deref(),
729 &self.grammar_registry,
730 &self.config.languages,
731 self.config.default_language.as_deref(),
732 );
733
734 let mut state = EditorState::from_buffer_with_language(buffer, detected);
735
736 state
737 .margins
738 .configure_for_line_numbers(self.config.editor.line_numbers);
739
740 self.windows
741 .get_mut(&self.active_window)
742 .map(|w| &mut w.buffers)
743 .expect("active window present")
744 .insert(buffer_id, state);
745 self.active_window_mut()
746 .event_logs
747 .insert(buffer_id, crate::model::event::EventLog::new());
748
749 let metadata = super::types::BufferMetadata::with_file(
750 path.to_path_buf(),
751 &display_path,
752 &self.working_dir,
753 self.authority.path_translation.as_ref(),
754 );
755 self.active_window_mut()
756 .buffer_metadata
757 .insert(buffer_id, metadata);
758
759 let target_split = self.active_window().preferred_split_for_file();
761 let line_wrap = self.active_window().resolve_line_wrap_for_buffer(buffer_id);
762 let wrap_column = self
763 .active_window()
764 .resolve_wrap_column_for_buffer(buffer_id);
765 if let Some(view_state) = self
766 .windows
767 .get_mut(&self.active_window)
768 .and_then(|w| w.split_view_states_mut())
769 .expect("active window must have a populated split layout")
770 .get_mut(&target_split)
771 {
772 view_state.add_buffer(buffer_id);
773 let buf_state = view_state.ensure_buffer_state(buffer_id);
774 buf_state.apply_config_defaults(
775 self.config.editor.line_numbers,
776 self.config.editor.highlight_current_line,
777 line_wrap,
778 self.config.editor.wrap_indent,
779 wrap_column,
780 self.config.editor.rulers.clone(),
781 );
782 }
783
784 self.set_active_buffer(buffer_id);
785
786 let display_name = self
788 .active_window()
789 .buffer_metadata
790 .get(&buffer_id)
791 .map(|m| m.display_name.clone())
792 .unwrap_or_else(|| path.display().to_string());
793
794 self.active_window_mut().status_message =
795 Some(t!("buffer.opened", name = display_name).to_string());
796
797 Ok(buffer_id)
798 }
799
800 pub(crate) fn open_lsp_uri_target(
830 &mut self,
831 uri: &crate::app::types::LspUri,
832 ) -> anyhow::Result<BufferId> {
833 let translation = self.authority.path_translation.clone();
834 let host_path = uri
835 .to_host_path(translation.as_ref())
836 .ok_or_else(|| anyhow::anyhow!("URI is not a file path"))?;
837
838 if self.authority.filesystem.exists(&host_path) {
844 return self.open_file(&host_path);
845 }
846
847 if translation.is_some() {
853 let container_path = uri.to_host_path(None).ok_or_else(|| {
858 anyhow::anyhow!("URI is not a file path (container-side decode failed)")
859 })?;
860 let buffer_id = self.fetch_and_open_container_file(container_path, uri.clone())?;
861 self.set_active_buffer(buffer_id);
865 return Ok(buffer_id);
866 }
867
868 Err(anyhow::anyhow!(
870 "could not open {}: file not found",
871 host_path.display()
872 ))
873 }
874
875 fn fetch_and_open_container_file(
885 &mut self,
886 container_path: std::path::PathBuf,
887 uri: crate::app::types::LspUri,
888 ) -> anyhow::Result<BufferId> {
889 let runtime = self.tokio_runtime.as_ref().ok_or_else(|| {
890 anyhow::anyhow!(
891 "could not open {}: no tokio runtime available for container fetch",
892 container_path.display()
893 )
894 })?;
895
896 let spawner = self.authority.process_spawner.clone();
897 let path_arg = container_path.to_string_lossy().into_owned();
898 let result = runtime
899 .block_on(spawner.spawn("cat".into(), vec![path_arg], None))
900 .map_err(|e| {
901 anyhow::anyhow!(
902 "could not open {} from container: {}",
903 container_path.display(),
904 e
905 )
906 })?;
907
908 if result.exit_code != 0 {
909 let first_stderr_line = result
910 .stderr
911 .lines()
912 .next()
913 .unwrap_or("(no error message)")
914 .trim();
915 anyhow::bail!(
916 "could not open {} from container: {}",
917 container_path.display(),
918 first_stderr_line
919 );
920 }
921
922 self.open_container_only_file(container_path, uri, result.stdout.into_bytes())
923 }
924
925 pub(crate) fn open_container_only_file(
932 &mut self,
933 container_path: std::path::PathBuf,
934 uri: crate::app::types::LspUri,
935 content: Vec<u8>,
936 ) -> anyhow::Result<BufferId> {
937 let already_open = self
940 .buffers()
941 .iter()
942 .find(|(_, state)| state.buffer.file_path() == Some(container_path.as_path()))
943 .map(|(id, _)| *id);
944 if let Some(id) = already_open {
945 return Ok(id);
946 }
947
948 let mut buffer = crate::model::buffer::Buffer::from_bytes(
953 content,
954 Arc::clone(&self.authority.filesystem),
955 );
956 buffer.rename_file_path(container_path.clone());
957
958 let first_line = buffer.first_line_lossy();
962 let detected =
963 crate::primitives::detected_language::DetectedLanguage::from_path_with_fallback(
964 &container_path,
965 first_line.as_deref(),
966 &self.grammar_registry,
967 &self.config.languages,
968 self.config.default_language.as_deref(),
969 );
970 let mut state = EditorState::from_buffer_with_language(buffer, detected);
971 state.editing_disabled = true;
972
973 let mut whitespace =
978 crate::config::WhitespaceVisibility::from_editor_config(&self.config.editor);
979 if let Some(lang_config) = self.config.languages.get(&state.language) {
980 whitespace = whitespace.with_language_tab_override(lang_config.show_whitespace_tabs);
981 state.buffer_settings.use_tabs =
982 lang_config.use_tabs.unwrap_or(self.config.editor.use_tabs);
983 state.buffer_settings.tab_size =
984 lang_config.tab_size.unwrap_or(self.config.editor.tab_size);
985 } else {
986 state.buffer_settings.tab_size = self.config.editor.tab_size;
987 state.buffer_settings.use_tabs = self.config.editor.use_tabs;
988 }
989 state.buffer_settings.whitespace = whitespace;
990 state
991 .margins
992 .configure_for_line_numbers(self.config.editor.line_numbers);
993
994 let buffer_id = self.alloc_buffer_id();
995 self.windows
996 .get_mut(&self.active_window)
997 .map(|w| &mut w.buffers)
998 .expect("active window present")
999 .insert(buffer_id, state);
1000 self.active_window_mut()
1001 .event_logs
1002 .insert(buffer_id, crate::model::event::EventLog::new());
1003
1004 let mut metadata =
1005 super::types::BufferMetadata::with_container_file(container_path.clone(), uri);
1006 self.notify_lsp_file_opened(&container_path, buffer_id, &mut metadata);
1011 self.active_window_mut()
1012 .buffer_metadata
1013 .insert(buffer_id, metadata);
1014
1015 let target_split = self.active_window().preferred_split_for_file();
1019 let line_wrap = self.active_window().resolve_line_wrap_for_buffer(buffer_id);
1020 let wrap_column = self
1021 .active_window()
1022 .resolve_wrap_column_for_buffer(buffer_id);
1023 if let Some(view_state) = self
1024 .windows
1025 .get_mut(&self.active_window)
1026 .and_then(|w| w.split_view_states_mut())
1027 .expect("active window must have a populated split layout")
1028 .get_mut(&target_split)
1029 {
1030 view_state.add_buffer(buffer_id);
1031 let buf_state = view_state.ensure_buffer_state(buffer_id);
1032 buf_state.apply_config_defaults(
1033 self.config.editor.line_numbers,
1034 self.config.editor.highlight_current_line,
1035 line_wrap,
1036 self.config.editor.wrap_indent,
1037 wrap_column,
1038 self.config.editor.rulers.clone(),
1039 );
1040 }
1041
1042 Ok(buffer_id)
1043 }
1044}