protected void paintSelection(Graphics g, FieldBackgroundColorManager colorManager, int row,
			int rowHeight) {

		List<Highlight> selections = colorManager.getSelectionHighlights(row);
		if (selections.isEmpty()) {
			return;
		}
		int textLength = getString().length();
		int endTextPos = findX(textLength);
		for (Highlight highlight : selections) {
			g.setColor(highlight.getColor());
			int startCol = highlight.getStart();
			int endCol = highlight.getEnd();
			int x1 = findX(startCol);
			int x2 = endCol < textLength ? findX(endCol) : endTextPos;
			g.fillRect(startX + x1, -getHeightAbove(), x2 - x1, getHeight());
		}

		Color rightMarginColor = colorManager.getPaddingColor(1);
		if (rightMarginColor != null) {
			g.setColor(rightMarginColor);
			g.fillRect(startX + endTextPos, -getHeightAbove(), width - endTextPos, rowHeight);
		}
	}
Checks if any of the textElements need to be clipped. If so, it creates a
new textElement for the element that needs to be clipped that will fit in
the available space. Any textElements past the clipped element will be
ignored.
Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/field/ClippingTextField.java