MCPcopy Create free account
hub / github.com/WheretIB/nullc / InputEnter

Method InputEnter

GUI/RichTextarea.cpp:1360–1391  ·  view source on GitHub ↗

Function that adds line break at the cursor position

Source from the content-addressed store, hash-verified

1358
1359// Function that adds line break at the cursor position
1360void TextareaData::InputEnter()
1361{
1362 // Increment line count
1363 lineCount++;
1364
1365 // Insert new line after current and switch to it
1366 currLine = InsertLineAfter(currLine);
1367
1368 currLine->data[0].style = currLine->prev->length ? currLine->prev->data[currLine->prev->length-1].style : 0;
1369
1370 // If line break is in the middle of the line
1371 if(cursorCharX != currLine->prev->length)
1372 {
1373 // Find, how much symbols will move to the next line
1374 unsigned int diff = currLine->prev->length - cursorCharX;
1375 // If it is more than the line can handle, extend character buffer
1376 ExtendLine(currLine, diff);
1377 // Copy symbols to the new line
1378 memcpy(currLine->data, &currLine->prev->data[cursorCharX], diff * sizeof(AreaChar));
1379 // Shrink old
1380 currLine->prev->length = cursorCharX;
1381 // Extend new
1382 currLine->length = diff;
1383 }
1384 // Move cursor to the next line
1385 cursorCharY++;
1386 cursorCharX = 0;
1387
1388 // Force redraw on the modified line and all that goes after it
1389 RECT invalid = { 0, (cursorCharY - shiftCharY - 1) * RichTextarea::charHeight, areaWidth, areaHeight };
1390 InvalidateRect(areaWnd, &invalid, false);
1391}
1392
1393// Windows scrollbar can scroll beyond valid positions
1394void TextareaData::ClampShift()

Callers 1

SetAreaTextMethod · 0.80

Calls 2

InsertLineAfterFunction · 0.85
ExtendLineFunction · 0.85

Tested by

no test coverage detected