@@ -1355,6 +1355,7 @@ fn append_mode(cx: &mut Context) {
13551355mod cmd {
13561356 use super::*;
13571357
1358+ use helix_dap::SourceBreakpoint;
13581359 use helix_view::editor::Action;
13591360 use ui::completers::{self, Completer};
13601361
@@ -1978,6 +1979,27 @@ mod cmd {
19781979 Ok(())
19791980 }
19801981
1982+ fn get_breakpoint_at_current_line(
1983+ cx: &mut compositor::Context,
1984+ ) -> Option<(usize, SourceBreakpoint)> {
1985+ let (view, doc) = current!(cx.editor);
1986+ let text = doc.text().slice(..);
1987+
1988+ let pos = doc.selection(view.id).primary().cursor(text);
1989+ let line = text.char_to_line(pos) + 1; // 1-indexing in DAP, 0-indexing in Helix
1990+ let path = match doc.path() {
1991+ Some(path) => path.to_path_buf(),
1992+ None => return None,
1993+ };
1994+ let vec = vec![];
1995+ let breakpoints = cx.editor.breakpoints.get(&path.clone()).unwrap_or(&vec);
1996+ let i = breakpoints.iter().position(|b| b.line == line);
1997+ match i {
1998+ Some(i) => Some((i, breakpoints.get(i).unwrap().clone())),
1999+ None => None,
2000+ }
2001+ }
2002+
19812003 fn edit_breakpoint_impl(
19822004 cx: &mut compositor::Context,
19832005 condition: Option<String>,
@@ -1985,15 +2007,7 @@ mod cmd {
19852007 ) -> anyhow::Result<()> {
19862008 use helix_lsp::block_on;
19872009
1988− let (view, doc) = current!(cx.editor);
1989− let text = doc.text().slice(..);
1990− let pos = doc.selection(view.id).primary().cursor(text);
1991− let breakpoint = helix_dap::SourceBreakpoint {
1992− line: text.char_to_line(pos) + 1, // convert from 0-indexing to 1-indexing (TODO: could set debugger to 0-indexing on init)
1993− condition,
1994− log_message,
1995− ..Default::default()
1996− };
2010+ let (_, doc) = current!(cx.editor);
19972011 let path = match doc.path() {
19982012 Some(path) => path.to_path_buf(),
19992013 None => {
@@ -2001,12 +2015,13 @@ mod cmd {
20012015 }
20022016 };
20032017
2004− let breakpoints = cx.editor.breakpoints.entry(path.clone()).or_default();
2005− if let Some(pos) = breakpoints.iter().position(|b| b.line == breakpoint.line) {
2018+ if let Some((pos, mut bp)) = get_breakpoint_at_current_line(cx) {
2019+ let breakpoints = cx.editor.breakpoints.entry(path.clone()).or_default();
20062020 breakpoints.remove(pos);
2007− breakpoints.push(breakpoint);
20082021
2009− let breakpoints = breakpoints.clone();
2022+ bp.condition = condition;
2023+ bp.log_message = log_message;
2024+ breakpoints.push(bp);
20102025
20112026 if let Some(debugger) = &mut cx.editor.debugger {
20122027 // TODO: handle capabilities correctly again, by filterin breakpoints when emitting
@@ -2032,7 +2047,7 @@ mod cmd {
20322047 // {
20332048 // bail!("Can't edit breakpoint: debugger does not support logpoints")
20342049 // }
2035− let request = debugger.set_breakpoints(path, breakpoints);
2050+ let request = debugger.set_breakpoints(path, breakpoints.clone());
20362051 if let Err(e) = block_on(request) {
20372052 bail!("Failed to set breakpoints: {:?}", e)
20382053 }