Request for deleteGroupForwardWin command

I’d appreciate it if you could put this into the codebase since I use the cursorGroupForwardWin and selectGroupForwardWin.

Here’s my implementation that seems to work OK:

/// Delete the selection forward in the default Windows style,
/// where it moves to the start of the next group.
export const deleteGroupForwardWin: StateCommand = target => deleteBy(target, range => {
  let pos = range.head, {state} = target, line = state.doc.lineAt(pos)
  let categorize = state.charCategorizer(pos)
  for (let cat: CharCategory | null = null;;) {
    if (pos == line.to) {
      if (pos == range.head && line.number != state.doc.lines)
        pos += 1
      break
    }
    let next = findClusterBreak(line.text, pos - line.from, true) + line.from
    let nextChar = line.text.slice(Math.min(pos, next) - line.from, Math.max(pos, next) - line.from)
    let nextCat = categorize(nextChar)
    if (cat != null && nextCat != cat && nextCat != CharCategory.Space) break
    cat = nextCat
    pos = next
  }
  return pos
})

Where the real difference from deleteByGroup is these lines:

(regular version)
    if (cat != null && nextCat != cat) break
    if (nextChar != " " ) cat = nextCat

(win version)
    if (cat != null && nextCat != cat && nextCat != CharCategory.Space) break
    cat = nextCat

The logic just says that any category change wants you to stop, except if you go into the space category. So this will allow whitespace following some non-whitespace group to be eaten upafter.

I’m not sure if there’s a reason to check “ “ instead of CharCategory.Space. I think the latter would also eat up tabs which you want?

What is the difference in behavior between this and deleteGroupForward?

It’s the same sort of thing between selectGroupForward and selectGroupForwardWin.

  1. deleteGroupForward will first delete whitespace (optionally), then delete either a category of word or other (similar to how the cursor/select group forward commands work).

  2. deleteGroupForwardWin would instead delete whitespace after a category of word or other (similar to how the “Win” variants for cursor/select group commands work).

If “|” is the cursor when doing the deleteGroupForward command…

oh| hello there

  1. this becomes: oh| there
  2. this becomes: oh|hello there

oh |hello there

  1. this becomes: oh | there
  2. this becomes: oh |there

Right, I see what you mean now. See this patch:

Thanks again!