Fix codeblock expansion initial state + refactor (#30539)
Release Notes: - N/A
This commit is contained in:
parent
68945ac53e
commit
5abca0f867
1 changed files with 18 additions and 15 deletions
|
@ -490,12 +490,7 @@ fn render_markdown_code_block(
|
||||||
let can_expand = metadata.line_count > MAX_UNCOLLAPSED_LINES_IN_CODE_BLOCK;
|
let can_expand = metadata.line_count > MAX_UNCOLLAPSED_LINES_IN_CODE_BLOCK;
|
||||||
|
|
||||||
let is_expanded = if can_expand {
|
let is_expanded = if can_expand {
|
||||||
active_thread
|
active_thread.read(cx).is_codeblock_expanded(message_id, ix)
|
||||||
.read(cx)
|
|
||||||
.expanded_code_blocks
|
|
||||||
.get(&(message_id, ix))
|
|
||||||
.copied()
|
|
||||||
.unwrap_or(false)
|
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
@ -582,11 +577,7 @@ fn render_markdown_code_block(
|
||||||
let active_thread = active_thread.clone();
|
let active_thread = active_thread.clone();
|
||||||
move |_event, _window, cx| {
|
move |_event, _window, cx| {
|
||||||
active_thread.update(cx, |this, cx| {
|
active_thread.update(cx, |this, cx| {
|
||||||
let is_expanded = this
|
this.toggle_codeblock_expanded(message_id, ix);
|
||||||
.expanded_code_blocks
|
|
||||||
.entry((message_id, ix))
|
|
||||||
.or_insert(true);
|
|
||||||
*is_expanded = !*is_expanded;
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2363,10 +2354,7 @@ impl ActiveThread {
|
||||||
|
|
||||||
let is_expanded = active_thread
|
let is_expanded = active_thread
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.expanded_code_blocks
|
.is_codeblock_expanded(message_id, range.start);
|
||||||
.get(&(message_id, range.start))
|
|
||||||
.copied()
|
|
||||||
.unwrap_or(false);
|
|
||||||
if is_expanded {
|
if is_expanded {
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
@ -3384,6 +3372,21 @@ impl ActiveThread {
|
||||||
.log_err();
|
.log_err();
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_codeblock_expanded(&self, message_id: MessageId, ix: usize) -> bool {
|
||||||
|
self.expanded_code_blocks
|
||||||
|
.get(&(message_id, ix))
|
||||||
|
.copied()
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn toggle_codeblock_expanded(&mut self, message_id: MessageId, ix: usize) {
|
||||||
|
let is_expanded = self
|
||||||
|
.expanded_code_blocks
|
||||||
|
.entry((message_id, ix))
|
||||||
|
.or_insert(false);
|
||||||
|
*is_expanded = !*is_expanded;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ActiveThreadEvent {
|
pub enum ActiveThreadEvent {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue