private int getEndOfWordIndex(JTextComponent textComponent, int offset)
			throws BadLocationException {

		Element currentParagraph = Utilities.getParagraphElement(textComponent, offset);
		int currentParagraphEndOffset = currentParagraph.getEndOffset();
		int currentParagraphEnd = currentParagraphEndOffset - 1;
		if (textComponent instanceof JPasswordField) {
			return currentParagraphEnd;
		}

		int wordOffset = offset;
		try {
			int startOfNextWord = Utilities.getNextWord(textComponent, offset);
			int endOfCurrentWord = Utilities.getWordEnd(textComponent, offset);
			boolean isWhiteSpace = startOfNextWord == endOfCurrentWord;
			if (isWhiteSpace) {
				wordOffset = Utilities.getWordEnd(textComponent, startOfNextWord);
			}
			else {
				wordOffset = endOfCurrentWord;
			}

			if (wordOffset >= currentParagraphEndOffset && offset != currentParagraphEnd) {
				wordOffset = currentParagraphEnd;
			}
		}
		catch (BadLocationException ble) {
			Document document = textComponent.getDocument();
			int documentEnd = document.getLength();
			if (wordOffset != documentEnd) {
				if (offset != currentParagraphEnd) {
					wordOffset = currentParagraphEnd;
				}
				else {
					wordOffset = documentEnd;
				}
			}
			else {
				throw ble;
			}
		}
		return wordOffset;
	}
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