From 6c11eca05bb700d4205387587ad3614ccf331d2a Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 14 Jul 2022 07:38:51 -0500 Subject: [PATCH] fix single line rsx hot reloading --- src/server/hot_reload.rs | 8 +++++++- src/server/mod.rs | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/server/hot_reload.rs b/src/server/hot_reload.rs index ea9c64fc7..40f556b00 100644 --- a/src/server/hot_reload.rs +++ b/src/server/hot_reload.rs @@ -113,7 +113,13 @@ pub async fn hot_reload_handler( *first = first.split_at(start.column).1; } if let Some(last) = lines.last_mut() { - *last = last.split_at(end.column).0; + // if there is only one line the start index of last line will be the start of the rsx!, not the start of the line + if start.line == end.line { + *last = + last.split_at(end.column - start.column).0; + } else { + *last = last.split_at(end.column).0; + } } let rsx = lines.join("\n"); messages.push(SetRsxMessage { diff --git a/src/server/mod.rs b/src/server/mod.rs index 387355ee9..fc35159c2 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -137,7 +137,13 @@ pub async fn startup_hot_reload(config: CrateConfig) -> Result<()> { *first = first.split_at(start.column).1; } if let Some(last) = lines.last_mut() { - *last = last.split_at(end.column).0; + // if there is only one line the start index of last line will be the start of the rsx!, not the start of the line + if start.line == end.line { + *last = + last.split_at(end.column - start.column).0; + } else { + *last = last.split_at(end.column).0; + } } let rsx = lines.join("\n"); messages.push(SetRsxMessage {