private int calcColumnOffset(int cursorColumn, int visibleColumns, int documentColumns, int currentLineColumns) { int columnOffset; if (WordWrap) { visibleColumns += 1; columnOffset = Math.Min(0, visibleColumns - 1 - cursorColumn); int extraColumns = 0; if (cursorColumn >= visibleColumns - 1) { extraColumns = -columnOffset + Math.Max(0, ImportedText.CountSpaces(TypedText.Length) - 1); } documentColumns = visibleColumns + extraColumns; } else { const int visibleColumnsBeforeJumpBack = 6; int jumpBackZone = Math.Max(1, visibleColumns - (visibleColumns / 2) + 2 - visibleColumnsBeforeJumpBack); columnOffset = calculateOffset(cursorColumn, visibleColumns, currentLineColumns, jumpBackZone); } var horizontalEventArgs = createVisibleRegionChangedEventArgs(columnOffset, visibleColumns, documentColumns); oldHorizontalEventArgs = Util.RaiseIfEventArgsChanged(OnHorizontalVisibleRegionChanged, horizontalEventArgs, oldHorizontalEventArgs); return(columnOffset); }