JBoolean JTEStyler::SetStyle ( const JIndexRange& range, const JFontStyle& style ) { assert( !range.IsEmpty() ); if (itsCheckRange.last < range.first) { // we are beyond the range where anything could have changed return kJFalse; } assert( range.first == itsTokenStart ); if (itsRedoAllFlag) { JFontID fid = itsDefFontID; if (!OnlyColorChanged(style, itsDefFontStyle)) { fid = itsFontMgr->GetFontID(itsFontName, itsFontSize, style); } itsStyles->AppendElements(JTextEditor::Font(fid, itsFontSize, style, itsDefFontAlign), range.GetLength()); } else if (range.last >= itsCheckRange.first) { JIndexRange fontRange; fontRange.SetFirstAndLength(itsTokenFirstInRun, itsStyles->GetRunLength(itsTokenRunIndex)); const JBoolean beyondCurrentRun = JNegate( fontRange.Contains(range) ); JTextEditor::Font f = itsStyles->GetRunData(itsTokenRunIndex); if (beyondCurrentRun || style != f.style) { // extend the check range if we slop over into another style run // (HTML: type '<' after 'x' in "x<!--<br><h3>text</h3>-->") // extend past end of run to insure that we keep going until we // find a correctly styled token if (beyondCurrentRun) { JIndex runIndex = itsTokenRunIndex; JIndex firstInRun = itsTokenFirstInRun; const JBoolean ok = itsStyles->FindRun(itsTokenStart, range.last, &runIndex, &firstInRun); ExtendCheckRange(firstInRun + itsStyles->GetRunLength(runIndex)); } // extend check range to next token since this token was not // correctly styled -- should only stop when find correctly // styled tokens else // style != f.style { ExtendCheckRange(range.last+1); } // update the styles if (!beyondCurrentRun && OnlyColorChanged(style, f.style)) { *itsRedrawRange += range; } else { *itsRecalcRange += range; } f.size = itsFontSize; f.style = style; if (OnlyColorChanged(style, itsDefFontStyle)) { f.id = itsDefFontID; } else { f.id = itsFontMgr->GetFontID(itsFontName, itsFontSize, style); } f.align = itsDefFontAlign; itsStyles->RemoveNextElements(range.first, range.GetLength(), &itsTokenRunIndex, &itsTokenFirstInRun); run_assert(itsStyles, range.first, itsTokenRunIndex, itsTokenFirstInRun); itsStyles->InsertElementsAtIndex(range.first, f, range.GetLength(), &itsTokenRunIndex, &itsTokenFirstInRun); run_assert(itsStyles, range.first, itsTokenRunIndex, itsTokenFirstInRun); } } itsTokenStart = range.last+1; if (!itsRedoAllFlag) { const JBoolean ok = itsStyles->FindRun(range.first, itsTokenStart, &itsTokenRunIndex, &itsTokenFirstInRun); assert( ok || range.last == itsText->GetLength() ); assert( range.last == itsText->GetLength() || check_run(itsStyles, itsTokenStart, itsTokenRunIndex, itsTokenFirstInRun) ); } return JConvertToBoolean( range.last < itsCheckRange.last ); }