本文整理汇总了C#中ITextPointer.CreateStaticPointer方法的典型用法代码示例。如果您正苦于以下问题:C# ITextPointer.CreateStaticPointer方法的具体用法?C# ITextPointer.CreateStaticPointer怎么用?C# ITextPointer.CreateStaticPointer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextPointer
的用法示例。
在下文中一共展示了ITextPointer.CreateStaticPointer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnContentRemoved
// Called when content is removed from the document.
// Update the run list and notifies the highlight layer.
private void OnContentRemoved(ITextPointer position)
{
int index;
int i;
Run run;
// Get the first bordering run.
index = FindIndex(position.CreateStaticPointer(), LogicalDirection.Backward);
if (index == -1)
{
// position is at beginning of document.
// Look at the first run.
index = 0;
}
// First run gets reset to dirty.
run = GetRun(index);
if (run.RunType != RunType.Dirty)
{
NotifyHighlightLayerBeforeRunChange(index);
run.RunType = RunType.Dirty; //
if (index > 0 && GetRun(index - 1).RunType == RunType.Dirty)
{
// Previous run matches the new value, merge with it.
_runList.RemoveAt(index);
index--;
}
}
// Start looking at the following runs.
index += 1;
// Middle runs (collapsed to zero width) are removed.
for (i = index; i < _runList.Count; i++)
{
ITextPointer runPosition = GetRun(i).Position;
// Stop if we find a non-bordering Run that is not empty.
if (runPosition.CompareTo(position) > 0 && runPosition.CompareTo(GetRunEndPosition(i)) != 0)
break;
}
// Note we don't worry about announcing anything to the HighlightLayer
// here because these are zero-width runs.
_runList.RemoveRange(index, i - index);
// Reset last run to dirty.
// Since we know the first run at index is already dirty,
// just remove it.
if (index < _runList.Count)
{
NotifyHighlightLayerBeforeRunChange(index);
_runList.RemoveAt(index); //
// Finally, merge the following run with the run at index
// if it happens to also be dirty.
if (index < _runList.Count && GetRun(index).RunType == RunType.Dirty)
{
_runList.RemoveAt(index);
}
}
}
示例2: GetFirstDirtyRange
// Returns the first dirty run following a specified position in the document.
// start/end will be left null if no dirty ranges are found.
internal void GetFirstDirtyRange(ITextPointer searchStart, out ITextPointer start, out ITextPointer end)
{
int index;
Run run;
start = null;
end = null;
// If this is ever slow enough to matter, we could cache the value.
for (index = FindIndex(searchStart.CreateStaticPointer(), LogicalDirection.Forward); index >= 0 && index < _runList.Count; index++)
{
run = GetRun(index);
if (run.RunType == RunType.Dirty)
{
// We might get a hit in the first run, in which case start <= searchStart.
// Always return searchStart as a minimum.
start = TextPointerBase.Max(searchStart, run.Position);
end = GetRunEndPositionDynamic(index);
break;
}
}
}
示例3: MarkRange
// Marks a text run as clean or dirty.
private void MarkRange(ITextPointer start, ITextPointer end, RunType runType)
{
if (start.CompareTo(end) == 0)
{
return;
}
int startIndex;
int endIndex;
Invariant.Assert(runType == RunType.Clean || runType == RunType.Dirty);
startIndex = FindIndex(start.CreateStaticPointer(), LogicalDirection.Forward);
endIndex = FindIndex(end.CreateStaticPointer(), LogicalDirection.Backward);
// We don't expect start/end to ever point off the edge of the document.
Invariant.Assert(startIndex >= 0);
Invariant.Assert(endIndex >= 0);
// Remove wholly covered runs.
if (startIndex + 1 < endIndex)
{
// Tell the HighlightLayer about any error runs that are going away.
for (int i = startIndex + 1; i < endIndex; i++)
{
NotifyHighlightLayerBeforeRunChange(i);
}
_runList.RemoveRange(startIndex + 1, endIndex - startIndex - 1);
endIndex = startIndex + 1;
}
// Merge the bordering edge runs.
if (startIndex == endIndex)
{
// We're contained in a single run.
AddRun(startIndex, start, end, runType);
}
else
{
// We cover two runs.
Invariant.Assert(startIndex == endIndex - 1);
// Handle the first run.
AddRun(startIndex, start, end, runType);
// Recalc endIndex, since it may have changed in the merge.
endIndex = FindIndex(end.CreateStaticPointer(), LogicalDirection.Backward);
Invariant.Assert(endIndex >= 0);
// Handle the second run.
AddRun(endIndex, start, end, runType);
}
}
示例4: MarkErrorRange
// Tags a run of text as an error.
// NB: we expect that the new error range has already been marked clean.
internal void MarkErrorRange(ITextPointer start, ITextPointer end)
{
int runIndex;
Run run;
runIndex = FindIndex(start.CreateStaticPointer(), LogicalDirection.Forward);
run = GetRun(runIndex);
// There should be a clean run here, that covers all the error.
// We always start analyzing text by cleaning the entire range.
Invariant.Assert(run.RunType == RunType.Clean);
Invariant.Assert(run.Position.CompareTo(start) <= 0);
Invariant.Assert(GetRunEndPosition(runIndex).CompareTo(end) >= 0);
if (run.Position.CompareTo(start) == 0)
{
// The run starts exactly at this error.
// Convert it to an error and add a second clean run for the remainder.
run.RunType = RunType.Error;
}
else
{
// The run starts before this error.
// Insert a new error run, and an additional run for the remainder.
_runList.Insert(runIndex + 1, new Run(start, RunType.Error));
runIndex++;
}
// Handle any remainder since we split the original clean run.
if (GetRunEndPosition(runIndex).CompareTo(end) > 0)
{
_runList.Insert(runIndex + 1, new Run(end, RunType.Clean));
}
// Tell the HighlightLayer about this change.
_highlightLayer.FireChangedEvent(start, end);
DebugAssertRunList();
}
示例5: GetNextSpellingErrorPosition
// Worker for TextBox/RichTextBox.GetNextSpellingErrorPosition.
// Returns the start position of the next error, or null if no error exists.
//
// NB: this method will force an evaluation of any dirty regions between
// position and the next error, which in the worst case is the rest of
// the document.
internal ITextPointer GetNextSpellingErrorPosition(ITextPointer position, LogicalDirection direction)
{
if (!EnsureInitialized())
return null;
StaticTextPointer endPosition;
SpellerStatusTable.RunType runType;
while (_statusTable.GetRun(position.CreateStaticPointer(), direction, out runType, out endPosition))
{
if (runType == SpellerStatusTable.RunType.Error)
break;
if (runType == SpellerStatusTable.RunType.Dirty)
{
ScanPosition(position, direction);
_statusTable.GetRun(position.CreateStaticPointer(), direction, out runType, out endPosition);
Invariant.Assert(runType != SpellerStatusTable.RunType.Dirty);
if (runType == SpellerStatusTable.RunType.Error)
break;
}
position = endPosition.CreateDynamicTextPointer(direction);
}
SpellingError spellingError = GetError(position, direction, false /* forceEvaluation */);
return spellingError == null ? null : spellingError.Start;
}
示例6: SearchForWordBreaks
private ITextPointer SearchForWordBreaks(ITextPointer position, LogicalDirection direction, XmlLanguage language, int minWordCount, bool stopOnError)
{
ITextPointer closestErrorPosition;
ITextPointer searchPosition;
ITextPointer start;
ITextPointer end;
StaticTextPointer nextErrorTransition;
int segmentCount;
TextMap textMap;
searchPosition = position.CreatePointer();
closestErrorPosition = null;
if (stopOnError)
{
nextErrorTransition = _statusTable.GetNextErrorTransition(position.CreateStaticPointer(), direction);
if (!nextErrorTransition.IsNull)
{
closestErrorPosition = nextErrorTransition.CreateDynamicTextPointer(LogicalDirection.Forward);
}
}
bool hitBreakPoint = false;
do
{
searchPosition.MoveByOffset(direction == LogicalDirection.Backward ? -ContextBlockSize : +ContextBlockSize);
// Don't go past closestErrorPosition.
if (closestErrorPosition != null)
{
if (direction == LogicalDirection.Backward && closestErrorPosition.CompareTo(searchPosition) > 0 ||
direction == LogicalDirection.Forward && closestErrorPosition.CompareTo(searchPosition) < 0)
{
searchPosition.MoveToPosition(closestErrorPosition);
hitBreakPoint = true;
}
}
// Don't venture into text in another language.
ITextPointer closestLanguageTransition = GetNextLanguageTransition(position, direction, language, searchPosition);
if (direction == LogicalDirection.Backward && closestLanguageTransition.CompareTo(searchPosition) > 0 ||
direction == LogicalDirection.Forward && closestLanguageTransition.CompareTo(searchPosition) < 0)
{
searchPosition.MoveToPosition(closestLanguageTransition);
hitBreakPoint = true;
}
if (direction == LogicalDirection.Backward)
{
start = searchPosition;
end = position;
}
else
{
start = position;
end = searchPosition;
}
textMap = new TextMap(start, end, start, end);
segmentCount = _spellerInterop.EnumTextSegments(textMap.Text, textMap.TextLength, null, null, null);
}
while (!hitBreakPoint &&
segmentCount < minWordCount + 1 &&
searchPosition.GetPointerContext(direction) != TextPointerContext.None);
return searchPosition;
}
示例7: GetError
// Returns an object holding state about an error at the specified
// position, or null if no error is present.
//
// If forceEvaluation is set true, the speller will analyze any dirty region
// covered by the position. Otherwise dirty regions will be treated as
// non-errors.
internal SpellingError GetError(ITextPointer position, LogicalDirection direction, bool forceEvaluation)
{
ITextPointer start;
ITextPointer end;
SpellingError error;
// Evaluate any pending dirty region.
if (forceEvaluation &&
EnsureInitialized() &&
_statusTable.IsRunType(position.CreateStaticPointer(), direction, SpellerStatusTable.RunType.Dirty))
{
ScanPosition(position, direction);
}
// Get the error result.
if (_statusTable != null &&
_statusTable.GetError(position.CreateStaticPointer(), direction, out start, out end))
{
error = new SpellingError(this, start, end);
}
else
{
error = null;
}
return error;
}