MCPcopy Create free account
hub / github.com/ZDoom/Raze / MakeStartPosGood

Method MakeStartPosGood

source/common/console/c_commandbuffer.cpp:122–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120
121
122void FCommandBuffer::MakeStartPosGood()
123{
124 // Make sure both values point to something valid.
125 if (CursorPos > Text.length()) CursorPos = (unsigned)Text.length();
126 if (StartPos > Text.length()) StartPos = (unsigned)Text.length();
127
128 CursorPosCells = CalcCellSize(CursorPos);
129 StartPosCells = CalcCellSize(StartPos);
130 unsigned LengthCells = CalcCellSize((unsigned)Text.length());
131
132 int n = StartPosCells;
133 unsigned cols = ConCols / active_con_scale(twod);
134
135 if (StartPosCells >= LengthCells)
136 { // Start of visible line is beyond end of line
137 n = CursorPosCells - cols + 2;
138 }
139 if ((CursorPosCells - StartPosCells) >= cols - 2)
140 { // The cursor is beyond the visible part of the line
141 n = CursorPosCells - cols + 2;
142 }
143 if (StartPosCells > CursorPosCells)
144 { // The cursor is in front of the visible part of the line
145 n = CursorPosCells;
146 }
147 StartPosCells = max(0, n);
148 bool overflow;
149 StartPos = CharsForCells(StartPosCells, &overflow);
150 if (overflow)
151 {
152 // We ended up in the middle of a double cell character, so set the start to the following character.
153 StartPosCells++;
154 StartPos = CharsForCells(StartPosCells, &overflow);
155 }
156}
157
158void FCommandBuffer::CursorStart()
159{

Callers 1

C_TabCompleteFunction · 0.80

Calls 2

active_con_scaleFunction · 0.85
lengthMethod · 0.80

Tested by

no test coverage detected