Find colored text

Everything related to our flagship word processor.
Post Reply
lreeve
Posts: 1
Joined: 2011-03-23 07:39:53

Find colored text

Post by lreeve » 2011-03-23 07:42:53

I've looked through the manual but can't find it. Is there a way to find a words or characters having colored text?
Any help appreciated.

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Find colored text

Post by Kino » 2011-03-23 08:17:23

If you want to find and select all texts in the same colour (manually applied, not defined in a style), put the insertion point somewhere in a text in that colour and choose ‘Select All’ from the pull-down menu (click on a coloured circle) in the status bar at the bottom of the document window.
SelectAllColor.png
SelectAllColor.png (20.07 KiB) Viewed 2577 times
If you want to find and select all texts in different colours, I think the macro below will do the job.

Code: Select all

 Require Pro Version 1.3
$doc = Document.active
if $doc == undefined
	exit
end

$black = Color.newWithRGBA 0, 0, 0, 1
$white = Color.newWithRGBA 1, 1, 1, 1
$colors = Hash.new
$samples = Array.new
$TC = Cast to String '[text] '
$BG = Cast to String '[back] '
$HL = Cast to String '[highlight] '
$sep = Cast to String '/'
$showSamples = Cast to String 'Show Samples'
$language = Language.systemLanguage

foreach $text in $doc.allTexts
	$textRanges = Array.new
	if $text.tables.count # then, exclude special texts enclosing tables
		$tableRanges = Array.new
		foreach $table in $text.tables
			$tableRanges.appendValue $table.enclosingTextRange
		end
		$tableRanges.sort
		$i = 0
		foreach $tableRange in $tableRanges
			$range = Range.newWithLocationAndBound $i, $tableRange.location
			$textRanges.appendValue $range
			$i = $tableRange.bound
		end
		$range = Range.newWithLocationAndBound $i, $text.length
	else
		$range = Range.new 0, $text.length
	end
	$textRanges.appendValue $range
	foreach $textRange in $textRanges
		$i = $textRange.location
		while $i < $textRange.bound
			$attr = $text.displayAttributesAtIndex $i
			$range = $text.rangeOfDisplayAttributesAtIndex $i
			$sel = TextSelection.new $text, $range
			if $attr.textColor != $black
				$key = $TC & $attr.textColor.hexTriplet
				$key &= $sep & $attr.textColor.opacity
				if $colors{$key} == undefined
					$colors{$key} = Array.new
					$sample = $key
					Push Target Text $sample
						Set Text Color $attr.textColor
					Pop Target Text
					$samples.appendValue $sample
				end
				$colors{$key}.appendValue $sel
			end
			if $attr.textBackgroundColor != $white
				$key = $BG & $attr.textBackgroundColor.hexTriplet
				$key &= $sep & $attr.textBackgroundColor.opacity
				if $colors{$key} == undefined
					$colors{$key} = Array.new
					$sample = $key
					Push Target Text $sample
						Set Background Color $attr.textBackgroundColor
					Pop Target Text
					$samples.appendValue $sample
				end
				$colors{$key}.appendValue $sel
			end
			if Defined $attr.textHighlightColor
				$key = $HL & $attr.textHighlightColor.hexTriplet
				$key &= $sep & $attr.textHighlightColor.opacity
				if $colors{$key} == undefined
					$colors{$key} = Array.new
					$sample = $key
					Push Target Text $sample
						Set Highlight Color $attr.textHighlightColor
					Pop Target Text
					$samples.appendValue $sample
				end
				$colors{$key}.appendValue $sel
			end
			$i = $range.bound
		end
	end
end

if ! $colors.keys.count
	exit 'No color found, exiting...'
end

$keys = $colors.keys
$keys.sort 'li', $language
$keys.appendValue $showSamples

$keys = Prompt Checkboxes '', '', '', $keys
if ! $keys.count
	exit # nothing checked
end

if $keys.lastValue == $showSamples
	$showSamples = true
	$keys.pop
end

if $keys.count
	$sels = Array.new
	foreach $key in $keys
		$sels.appendValuesFromArray $colors{$key}
	end
	$doc.setSelections $sels
end

if $showSamples == true
	$LF = Cast to String "\n"
	$samples.sort 'li', $language
	$samples = $samples.join $LF
	Document.newWithText $samples
end
SelectByColor_20110324_nwm.zip
(4.95 KiB) Downloaded 240 times
In either case, if you need looking at each one of selected texts, adding Bookmarks to them (Insert:Bookmarks:Add Bookmark) and visiting them one by one from Navigator (View:Show Navigator and switch to Bookmarks from Table of Content) would be handy.

User avatar
martin
Official Nisus Person
Posts: 4251
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Find colored text

Post by martin » 2011-03-23 12:07:05

Kino's macro and tip about the color tag's "select all" menu are a good way to go. Another option is to use attribute sensitive search:

1. Open the Find and Replace dialog.
2. By the "find what" field, click the gear icon to insert a PowerFind bubble for Wild Card > AnyText.
3. Select that bubble and use the formatting menus (eg: Format > Text Color > Red).
(Applying formatting to the bubble should automatically turn on the "attribute sensitive" option just below)
4. Use the Find Next / Find All buttons as you normally would.

Post Reply