@@ -231,10 +231,11 @@ fn cell_param(p: &Value, key: &str) -> Option<(usize, usize)> {
231231}
232232
233233/// The table's row/col to act on: params, the edited cell, or the selected cells.
234- fn at ( s : & Session , p : & Value ) -> ( usize , usize ) {
234+ /// A present but invalid `row`/`col` is an error; only an absent one falls back.
235+ fn at ( s : & Session , p : & Value , cmd : & str ) -> Result < ( usize , usize ) > {
235236 let st = s. active ( ) ;
236237 let cell = st. and_then ( |d| d. selection . text . as_ref ( ) . and_then ( |t| t. cell ) ) . or_else ( || st. and_then ( |d| d. selection . cells . map ( |c| c. 1 ) ) ) ;
237- ( usize_param ( p, "row" ) . or ( cell. map ( |c| c. 0 ) ) . unwrap_or ( 0 ) , usize_param ( p, "col" ) . or ( cell. map ( |c| c. 1 ) ) . unwrap_or ( 0 ) )
238+ Ok ( ( opt_usize_param ( p, "row" , cmd ) ? . or ( cell. map ( |c| c. 0 ) ) . unwrap_or ( 0 ) , opt_usize_param ( p, "col" , cmd ) ? . or ( cell. map ( |c| c. 1 ) ) . unwrap_or ( 0 ) ) )
238239}
239240
240241fn with_table ( s : & mut Session , p : & Value , cmd : & str , f : impl Fn ( & mut Table ) -> Result < ( ) > ) -> Result < Value > {
@@ -283,7 +284,7 @@ fn with_table(s: &mut Session, p: &Value, cmd: &str, f: impl Fn(&mut Table) -> R
283284}
284285
285286fn rows_cols ( s : & mut Session , p : & Value , op : & str ) -> Result < Value > {
286- let ( r, c) = at ( s, p) ;
287+ let ( r, c) = at ( s, p, & format ! ( "table.{op}" ) ) ? ;
287288 let op = op. to_string ( ) ;
288289 with_table ( s, p, "table" , move |t| {
289290 match op. as_str ( ) {
@@ -319,7 +320,10 @@ fn merge(s: &mut Session, p: &Value) -> Result<Value> {
319320}
320321
321322fn split ( s : & mut Session , p : & Value ) -> Result < Value > {
322- let cell = cell_param ( p, "cell" ) . unwrap_or_else ( || at ( s, p) ) ;
323+ let cell = match cell_param ( p, "cell" ) {
324+ Some ( c) => c,
325+ None => at ( s, p, "table.split" ) ?,
326+ } ;
323327 with_table ( s, p, "table.split" , move |t| if t. split ( cell. 0 , cell. 1 ) { Ok ( ( ) ) } else { Err ( bad ( "table.split" , "that cell isn't merged" ) ) } )
324328}
325329
@@ -531,7 +535,7 @@ fn distribute(s: &mut Session, p: &Value, rows: bool) -> Result<Value> {
531535}
532536
533537fn column_width ( s : & mut Session , p : & Value ) -> Result < Value > {
534- let ( _, c) = at ( s, p) ;
538+ let ( _, c) = at ( s, p, "table.columnWidth" ) ? ;
535539 let w = f64_param ( p, "width" ) . ok_or_else ( || bad ( "table.columnWidth" , "missing `width`" ) ) ?. clamp ( 4.0 , 4000.0 ) ;
536540 let keep_total = bool_or ( p, "keepTotal" , false ) ;
537541 with_table ( s, p, "table.columnWidth" , move |t| {
@@ -560,7 +564,7 @@ fn column_width(s: &mut Session, p: &Value) -> Result<Value> {
560564}
561565
562566fn row_height ( s : & mut Session , p : & Value ) -> Result < Value > {
563- let ( r, _) = at ( s, p) ;
567+ let ( r, _) = at ( s, p, "table.rowHeight" ) ? ;
564568 let h = f64_param ( p, "height" ) . ok_or_else ( || bad ( "table.rowHeight" , "missing `height`" ) ) ?. clamp ( 4.0 , 4000.0 ) ;
565569 with_table ( s, p, "table.rowHeight" , move |t| {
566570 if let Some ( x) = t. rows . get_mut ( r) {
0 commit comments