First pass on fixes

This commit is contained in:
Piotr Osiewicz 2025-08-19 14:23:59 +02:00
parent 5826d89b97
commit 2f3be75fc7
269 changed files with 1593 additions and 2574 deletions

View file

@ -300,14 +300,13 @@ impl<'a> MarkdownParser<'a> {
if style != MarkdownHighlightStyle::default() && last_run_len < text.len() {
let mut new_highlight = true;
if let Some((last_range, last_style)) = highlights.last_mut() {
if last_range.end == last_run_len
if let Some((last_range, last_style)) = highlights.last_mut()
&& last_range.end == last_run_len
&& last_style == &MarkdownHighlight::Style(style.clone())
{
last_range.end = text.len();
new_highlight = false;
}
}
if new_highlight {
highlights.push((
last_run_len..text.len(),
@ -579,11 +578,10 @@ impl<'a> MarkdownParser<'a> {
}
} else {
let block = self.parse_block().await;
if let Some(block) = block {
if let Some(list_item) = items_stack.last_mut() {
if let Some(block) = block
&& let Some(list_item) = items_stack.last_mut() {
list_item.content.extend(block);
}
}
}
}

View file

@ -151,11 +151,9 @@ impl MarkdownPreviewView {
if let Some(editor) = workspace
.active_item(cx)
.and_then(|item| item.act_as::<Editor>(cx))
{
if Self::is_markdown_file(&editor, cx) {
&& Self::is_markdown_file(&editor, cx) {
return Some(editor);
}
}
None
}
@ -243,33 +241,28 @@ impl MarkdownPreviewView {
window: &mut Window,
cx: &mut Context<Self>,
) {
if let Some(item) = active_item {
if item.item_id() != cx.entity_id() {
if let Some(editor) = item.act_as::<Editor>(cx) {
if Self::is_markdown_file(&editor, cx) {
if let Some(item) = active_item
&& item.item_id() != cx.entity_id()
&& let Some(editor) = item.act_as::<Editor>(cx)
&& Self::is_markdown_file(&editor, cx) {
self.set_editor(editor, window, cx);
}
}
}
}
}
pub fn is_markdown_file<V>(editor: &Entity<Editor>, cx: &mut Context<V>) -> bool {
let buffer = editor.read(cx).buffer().read(cx);
if let Some(buffer) = buffer.as_singleton() {
if let Some(language) = buffer.read(cx).language() {
if let Some(buffer) = buffer.as_singleton()
&& let Some(language) = buffer.read(cx).language() {
return language.name() == "Markdown".into();
}
}
false
}
fn set_editor(&mut self, editor: Entity<Editor>, window: &mut Window, cx: &mut Context<Self>) {
if let Some(active) = &self.active_editor {
if active.editor == editor {
if let Some(active) = &self.active_editor
&& active.editor == editor {
return;
}
}
let subscription = cx.subscribe_in(
&editor,
@ -552,8 +545,8 @@ impl Render for MarkdownPreviewView {
.group("markdown-block")
.on_click(cx.listener(
move |this, event: &ClickEvent, window, cx| {
if event.click_count() == 2 {
if let Some(source_range) = this
if event.click_count() == 2
&& let Some(source_range) = this
.contents
.as_ref()
.and_then(|c| c.children.get(ix))
@ -567,7 +560,6 @@ impl Render for MarkdownPreviewView {
source_range.start..source_range.start,
);
}
}
},
))
.map(move |container| {