refactor(gui): Use imscope context managers in _render_discussion_entry_read_mode
This commit is contained in:
+8
-12
@@ -1422,9 +1422,8 @@ class App:
|
|||||||
pattern = re.compile(r"\[Definition: (.*?) from (.*?) \(line (\d+)\)\](\s+```[\s\S]*?```)?")
|
pattern = re.compile(r"\[Definition: (.*?) from (.*?) \(line (\d+)\)\](\s+```[\s\S]*?```)?")
|
||||||
matches, is_nerv = list(pattern.finditer(content)), theme.is_nerv_active()
|
matches, is_nerv = list(pattern.finditer(content)), theme.is_nerv_active()
|
||||||
if not matches:
|
if not matches:
|
||||||
if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80))
|
with imscope.style_color(imgui.Col_.text, vec4(80, 255, 80)) if is_nerv else nullcontext():
|
||||||
markdown_helper.render(content, context_id=f'disc_{index}')
|
markdown_helper.render(content, context_id=f'disc_{index}')
|
||||||
if is_nerv: imgui.pop_style_color()
|
|
||||||
else:
|
else:
|
||||||
with imscope.child(f"read_content_{index}", size_y=150, flags=True):
|
with imscope.child(f"read_content_{index}", size_y=150, flags=True):
|
||||||
if self.ui_word_wrap: imgui.push_text_wrap_pos(imgui.get_content_region_avail().x)
|
if self.ui_word_wrap: imgui.push_text_wrap_pos(imgui.get_content_region_avail().x)
|
||||||
@@ -1432,24 +1431,21 @@ class App:
|
|||||||
for m_idx, match in enumerate(matches):
|
for m_idx, match in enumerate(matches):
|
||||||
before = content[last_idx:match.start()]
|
before = content[last_idx:match.start()]
|
||||||
if before:
|
if before:
|
||||||
if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80))
|
with imscope.style_color(imgui.Col_.text, vec4(80, 255, 80)) if is_nerv else nullcontext():
|
||||||
markdown_helper.render(before, context_id=f'disc_{index}_b_{m_idx}')
|
markdown_helper.render(before, context_id=f'disc_{index}_b_{m_idx}')
|
||||||
if is_nerv: imgui.pop_style_color()
|
|
||||||
header_text, path, code_block = match.group(0).split("\n")[0].strip(), match.group(2), match.group(4)
|
header_text, path, code_block = match.group(0).split("\n")[0].strip(), match.group(2), match.group(4)
|
||||||
if imgui.collapsing_header(header_text):
|
if imgui.collapsing_header(header_text):
|
||||||
if imgui.button(f"[Source]##{index}_{match.start()}"):
|
if imgui.button(f"[Source]##{index}_{match.start()}"):
|
||||||
res = mcp_client.read_file(path)
|
res = mcp_client.read_file(path)
|
||||||
if res: self.text_viewer_title, self.text_viewer_content, self.text_viewer_type, self.show_text_viewer = path, res, (Path(path).suffix.lstrip('.') if Path(path).suffix else 'text'), True
|
if res: self.text_viewer_title, self.text_viewer_content, self.text_viewer_type, self.show_text_viewer = path, res, (Path(path).suffix.lstrip('.') if Path(path).suffix else 'text'), True
|
||||||
if code_block:
|
if code_block:
|
||||||
if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80))
|
with imscope.style_color(imgui.Col_.text, vec4(80, 255, 80)) if is_nerv else nullcontext():
|
||||||
markdown_helper.render(code_block, context_id=f'disc_{index}_c_{m_idx}')
|
markdown_helper.render(code_block, context_id=f'disc_{index}_c_{m_idx}')
|
||||||
if is_nerv: imgui.pop_style_color()
|
|
||||||
last_idx = match.end()
|
last_idx = match.end()
|
||||||
after = content[last_idx:]
|
after = content[last_idx:]
|
||||||
if after:
|
if after:
|
||||||
if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80))
|
with imscope.style_color(imgui.Col_.text, vec4(80, 255, 80)) if is_nerv else nullcontext():
|
||||||
markdown_helper.render(after, context_id=f'disc_{index}_a')
|
markdown_helper.render(after, context_id=f'disc_{index}_a')
|
||||||
if is_nerv: imgui.pop_style_color()
|
|
||||||
if self.ui_word_wrap: imgui.pop_text_wrap_pos()
|
if self.ui_word_wrap: imgui.pop_text_wrap_pos()
|
||||||
|
|
||||||
def _render_mma_focus_selector(self) -> None:
|
def _render_mma_focus_selector(self) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user