@Override
	public void actionPerformed(ActionEvent e) {
		JTextComponent textComponent = getTextComponent(e);
		if (textComponent == null || !textComponent.isEditable()) {
			error(textComponent);
			return;
		}

		try {
			Document document = textComponent.getDocument();
			Caret caret = textComponent.getCaret();
			int caretIndex = caret.getDot();
			int markIndex = caret.getMark();

			int selectionStartIndex = Math.min(caretIndex, markIndex);
			int selectionEndIndex = Math.max(caretIndex, markIndex);
			int wordEndIndex = getEndOfWordIndex(textComponent, selectionStartIndex);

			if (wordEndIndex != selectionEndIndex) {
				document.remove(selectionStartIndex, wordEndIndex - selectionStartIndex);
			}
			else if (caretIndex > 0) {
				error(textComponent);
			}
		}
		catch (BadLocationException ble) {
			error(textComponent);
		}
	}
An action to delete from the cursor position to the end of the current word.
Ghidra/Framework/Generic/src/main/java/generic/util/action/DeleteToEndOfWordAction.java