Skip to repository content379 lines · 13.3 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T01:33:36.315Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
config.rs
1use super::*;
2
3impl Editor {
4 pub fn style(&mut self, cx: &App) -> &EditorStyle {
5 match self.style {
6 Some(ref style) => style,
7 None => {
8 let style = self.create_style(cx);
9 self.style.insert(style)
10 }
11 }
12 }
13
14 pub fn set_soft_wrap_mode(
15 &mut self,
16 mode: language_settings::SoftWrap,
17 cx: &mut Context<Self>,
18 ) {
19 self.soft_wrap_mode_override = Some(mode);
20 cx.notify();
21 }
22
23 pub fn set_hard_wrap(&mut self, hard_wrap: Option<usize>, cx: &mut Context<Self>) {
24 self.hard_wrap = hard_wrap;
25 cx.notify();
26 }
27
28 pub fn set_text_style_refinement(&mut self, style: TextStyleRefinement) {
29 self.text_style_refinement = Some(style);
30 }
31
32 /// called by the Element so we know what style we were most recently rendered with.
33 pub fn set_style(&mut self, style: EditorStyle, window: &mut Window, cx: &mut Context<Self>) {
34 // We intentionally do not inform the display map about the minimap style
35 // so that wrapping is not recalculated and stays consistent for the editor
36 // and its linked minimap.
37 if !self.mode.is_minimap() {
38 let font = style.text.font();
39 let font_size = style.text.font_size.to_pixels(window.rem_size());
40 let display_map = self
41 .placeholder_display_map
42 .as_ref()
43 .filter(|_| self.is_empty(cx))
44 .unwrap_or(&self.display_map);
45
46 display_map.update(cx, |map, cx| map.set_font(font, font_size, cx));
47 }
48 self.style = Some(style);
49 }
50
51 pub fn set_soft_wrap(&mut self) {
52 self.soft_wrap_mode_override = Some(language_settings::SoftWrap::EditorWidth)
53 }
54
55 pub fn set_show_wrap_guides(&mut self, show_wrap_guides: bool, cx: &mut Context<Self>) {
56 self.show_wrap_guides = Some(show_wrap_guides);
57 cx.notify();
58 }
59
60 pub fn set_show_indent_guides(&mut self, show_indent_guides: bool, cx: &mut Context<Self>) {
61 self.show_indent_guides = Some(show_indent_guides);
62 cx.notify();
63 }
64
65 pub fn disable_indent_guides_for_buffer(
66 &mut self,
67 buffer_id: BufferId,
68 cx: &mut Context<Self>,
69 ) {
70 self.buffers_with_disabled_indent_guides.insert(buffer_id);
71 cx.notify();
72 }
73
74 pub fn toggle_line_numbers(
75 &mut self,
76 _: &ToggleLineNumbers,
77 _: &mut Window,
78 cx: &mut Context<Self>,
79 ) {
80 let mut editor_settings = EditorSettings::get_global(cx).clone();
81 editor_settings.gutter.line_numbers = !editor_settings.gutter.line_numbers;
82 EditorSettings::override_global(editor_settings, cx);
83 }
84
85 pub fn line_numbers_enabled(&self, cx: &App) -> bool {
86 if let Some(show_line_numbers) = self.show_line_numbers {
87 return show_line_numbers;
88 }
89 EditorSettings::get_global(cx).gutter.line_numbers
90 }
91
92 pub fn relative_line_numbers(&self, cx: &App) -> RelativeLineNumbers {
93 match (
94 self.use_relative_line_numbers,
95 EditorSettings::get_global(cx).relative_line_numbers,
96 ) {
97 (None, setting) => setting,
98 (Some(false), _) => RelativeLineNumbers::Disabled,
99 (Some(true), RelativeLineNumbers::Wrapped) => RelativeLineNumbers::Wrapped,
100 (Some(true), _) => RelativeLineNumbers::Enabled,
101 }
102 }
103
104 pub fn set_relative_line_number(&mut self, is_relative: Option<bool>, cx: &mut Context<Self>) {
105 self.use_relative_line_numbers = is_relative;
106 cx.notify();
107 }
108
109 pub fn set_show_gutter(&mut self, show_gutter: bool, cx: &mut Context<Self>) {
110 self.show_gutter = show_gutter;
111 cx.notify();
112 }
113
114 pub fn set_show_vertical_scrollbar(&mut self, show: bool, cx: &mut Context<Self>) {
115 self.show_scrollbars.vertical = show;
116 cx.notify();
117 }
118
119 pub fn set_show_horizontal_scrollbar(&mut self, show: bool, cx: &mut Context<Self>) {
120 self.show_scrollbars.horizontal = show;
121 cx.notify();
122 }
123
124 pub fn set_minimap_visibility(
125 &mut self,
126 minimap_visibility: MinimapVisibility,
127 window: &mut Window,
128 cx: &mut Context<Self>,
129 ) {
130 if self.minimap_visibility != minimap_visibility {
131 if minimap_visibility.visible() && self.minimap.is_none() {
132 let minimap_settings = EditorSettings::get_global(cx).minimap;
133 self.minimap =
134 self.create_minimap(minimap_settings.with_show_override(), window, cx);
135 }
136 self.minimap_visibility = minimap_visibility;
137 cx.notify();
138 }
139 }
140
141 pub fn breadcrumbs_visible(&self) -> bool {
142 self.breadcrumbs_visibility.visible()
143 }
144
145 fn set_breadcrumbs_visibility(
146 &mut self,
147 breadcrumbs_visibility: BreadcrumbsVisibility,
148 cx: &mut Context<Self>,
149 ) {
150 if self.breadcrumbs_visibility != breadcrumbs_visibility {
151 self.breadcrumbs_visibility = breadcrumbs_visibility;
152 cx.emit(EditorEvent::BreadcrumbsChanged);
153 cx.notify();
154 }
155 }
156
157 pub fn toggle_breadcrumb(
158 &mut self,
159 _: &ToggleBreadcrumb,
160 _: &mut Window,
161 cx: &mut Context<Self>,
162 ) {
163 self.set_breadcrumbs_visibility(self.breadcrumbs_visibility.toggle_visibility(), cx);
164 }
165
166 pub fn disable_scrollbars_and_minimap(&mut self, window: &mut Window, cx: &mut Context<Self>) {
167 self.set_show_scrollbars(false, cx);
168 self.set_minimap_visibility(MinimapVisibility::Disabled, window, cx);
169 }
170
171 pub fn hide_minimap_by_default(&mut self, window: &mut Window, cx: &mut Context<Self>) {
172 self.set_minimap_visibility(self.minimap_visibility.hidden(), window, cx);
173 }
174
175 /// Normally the text in full mode and auto height editors is padded on the
176 /// left side by roughly half a character width for improved hit testing.
177 ///
178 /// Use this method to disable this for cases where this is not wanted (e.g.
179 /// if you want to align the editor text with some other text above or below)
180 /// or if you want to add this padding to single-line editors.
181 pub fn set_offset_content(&mut self, offset_content: bool, cx: &mut Context<Self>) {
182 self.offset_content = offset_content;
183 cx.notify();
184 }
185
186 pub fn set_show_line_numbers(&mut self, show_line_numbers: bool, cx: &mut Context<Self>) {
187 self.show_line_numbers = Some(show_line_numbers);
188 cx.notify();
189 }
190
191 pub fn disable_expand_excerpt_buttons(&mut self, cx: &mut Context<Self>) {
192 self.disable_expand_excerpt_buttons = true;
193 cx.notify();
194 }
195
196 pub fn set_show_git_diff_gutter(&mut self, show_git_diff_gutter: bool, cx: &mut Context<Self>) {
197 self.show_git_diff_gutter = Some(show_git_diff_gutter);
198 cx.notify();
199 }
200
201 pub fn set_allow_git_diff_scrollbar_markers(&mut self, allow: bool, cx: &mut Context<Self>) {
202 if self.allow_git_diff_scrollbar_markers != allow {
203 self.allow_git_diff_scrollbar_markers = allow;
204 self.scrollbar_marker_state.dirty = true;
205 self.scrollbar_marker_state.markers = Default::default();
206 self.scrollbar_marker_state.pending_refresh = None;
207 cx.notify();
208 }
209 }
210
211 pub fn set_show_code_actions(&mut self, show_code_actions: bool, cx: &mut Context<Self>) {
212 self.show_code_actions = Some(show_code_actions);
213 cx.notify();
214 }
215
216 pub fn set_show_runnables(&mut self, show_runnables: bool, cx: &mut Context<Self>) {
217 self.show_runnables = Some(show_runnables);
218 cx.notify();
219 }
220
221 pub fn set_show_breakpoints(&mut self, show_breakpoints: bool, cx: &mut Context<Self>) {
222 self.show_breakpoints = Some(show_breakpoints);
223 cx.notify();
224 }
225
226 pub fn set_show_diff_review_button(&mut self, show: bool, cx: &mut Context<Self>) {
227 self.show_diff_review_button = show;
228 cx.notify();
229 }
230
231 fn set_show_scrollbars(&mut self, show: bool, cx: &mut Context<Self>) {
232 self.show_scrollbars = ScrollbarAxes {
233 horizontal: show,
234 vertical: show,
235 };
236 cx.notify();
237 }
238
239 pub(super) fn wrap_guides(&self, cx: &App) -> SmallVec<[(usize, bool); 2]> {
240 let mut wrap_guides = smallvec![];
241
242 if self.show_wrap_guides == Some(false) {
243 return wrap_guides;
244 }
245
246 let settings = self.buffer.read(cx).language_settings(cx);
247 if settings.show_wrap_guides {
248 match self.soft_wrap_mode(cx) {
249 SoftWrap::Bounded(soft_wrap) => {
250 wrap_guides.push((soft_wrap as usize, true));
251 }
252 SoftWrap::GitDiff | SoftWrap::None | SoftWrap::EditorWidth => {}
253 }
254 wrap_guides.extend(settings.wrap_guides.iter().map(|guide| (*guide, false)))
255 }
256
257 wrap_guides
258 }
259
260 pub fn soft_wrap_mode(&self, cx: &App) -> SoftWrap {
261 let settings = self.buffer.read(cx).language_settings(cx);
262 let mode = self.soft_wrap_mode_override.unwrap_or(settings.soft_wrap);
263 match mode {
264 language_settings::SoftWrap::PreferLine | language_settings::SoftWrap::None => {
265 SoftWrap::None
266 }
267 language_settings::SoftWrap::EditorWidth => SoftWrap::EditorWidth,
268 language_settings::SoftWrap::Bounded => {
269 SoftWrap::Bounded(settings.preferred_line_length)
270 }
271 }
272 }
273
274 // Called by the element. This method is not designed to be called outside of the editor
275 // element's layout code because it does not notify when rewrapping is computed synchronously.
276 pub(super) fn set_wrap_width(&self, width: Option<Pixels>, cx: &mut App) -> bool {
277 if self.is_empty(cx) {
278 self.placeholder_display_map
279 .as_ref()
280 .map_or(false, |display_map| {
281 display_map.update(cx, |map, cx| map.set_wrap_width(width, cx))
282 })
283 } else {
284 self.display_map
285 .update(cx, |map, cx| map.set_wrap_width(width, cx))
286 }
287 }
288
289 pub fn toggle_soft_wrap(&mut self, _: &ToggleSoftWrap, _: &mut Window, cx: &mut Context<Self>) {
290 if self.soft_wrap_mode_override.is_some() {
291 self.soft_wrap_mode_override.take();
292 } else {
293 let soft_wrap = match self.soft_wrap_mode(cx) {
294 SoftWrap::GitDiff => return,
295 SoftWrap::None => language_settings::SoftWrap::EditorWidth,
296 SoftWrap::EditorWidth | SoftWrap::Bounded(_) => language_settings::SoftWrap::None,
297 };
298 self.soft_wrap_mode_override = Some(soft_wrap);
299 }
300 cx.notify();
301 }
302
303 pub(super) fn toggle_tab_bar(
304 &mut self,
305 _: &ToggleTabBar,
306 _: &mut Window,
307 cx: &mut Context<Self>,
308 ) {
309 let Some(workspace) = self.workspace() else {
310 return;
311 };
312 let fs = workspace.read(cx).app_state().fs.clone();
313 let current_show = TabBarSettings::get_global(cx).show;
314 update_settings_file(fs, cx, move |setting, _| {
315 setting.tab_bar.get_or_insert_default().show = Some(!current_show);
316 });
317 }
318
319 pub(super) fn toggle_indent_guides(
320 &mut self,
321 _: &ToggleIndentGuides,
322 _: &mut Window,
323 cx: &mut Context<Self>,
324 ) {
325 let currently_enabled = self.should_show_indent_guides().unwrap_or_else(|| {
326 self.buffer
327 .read(cx)
328 .language_settings(cx)
329 .indent_guides
330 .enabled
331 });
332 self.show_indent_guides = Some(!currently_enabled);
333 cx.notify();
334 }
335
336 pub(super) fn should_show_indent_guides(&self) -> Option<bool> {
337 self.show_indent_guides
338 }
339
340 pub(super) fn has_indent_guides_disabled_for_buffer(&self, buffer_id: BufferId) -> bool {
341 self.buffers_with_disabled_indent_guides
342 .contains(&buffer_id)
343 }
344
345 pub(super) fn toggle_relative_line_numbers(
346 &mut self,
347 _: &ToggleRelativeLineNumbers,
348 _: &mut Window,
349 cx: &mut Context<Self>,
350 ) {
351 let is_relative = self.relative_line_numbers(cx);
352 self.set_relative_line_number(Some(!is_relative.enabled()), cx)
353 }
354
355 pub(super) fn set_number_deleted_lines(&mut self, number: bool, cx: &mut Context<Self>) {
356 self.number_deleted_lines = number;
357 cx.notify();
358 }
359
360 pub fn set_delegate_open_excerpts(&mut self, delegate: bool) {
361 self.delegate_open_excerpts = delegate;
362 }
363
364 pub(super) fn set_delegate_expand_excerpts(&mut self, delegate: bool) {
365 self.delegate_expand_excerpts = delegate;
366 }
367
368 pub(super) fn set_on_local_selections_changed(
369 &mut self,
370 callback: Option<Box<dyn Fn(Point, &mut Window, &mut Context<Self>) + 'static>>,
371 ) {
372 self.on_local_selections_changed = callback;
373 }
374
375 pub(super) fn set_suppress_selection_callback(&mut self, suppress: bool) {
376 self.suppress_selection_callback = suppress;
377 }
378}
379