mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
fix pos being wrong
This commit is contained in:
parent
d678d8c9e4
commit
7c8c8c645b
@ -152,30 +152,31 @@ namespace Bloxstrap.UI.Elements.Editor
|
|||||||
private (string, int) GetLineAndPosAtCaretPosition()
|
private (string, int) GetLineAndPosAtCaretPosition()
|
||||||
{
|
{
|
||||||
// this assumes the file was saved as CSLF (\r\n newlines)
|
// this assumes the file was saved as CSLF (\r\n newlines)
|
||||||
int lineStartIdx = UIXML.Text.LastIndexOf('\n', UIXML.CaretOffset - 1);
|
int offset = UIXML.CaretOffset - 1;
|
||||||
int lineEndIdx = UIXML.Text.IndexOf('\n', UIXML.CaretOffset - 1);
|
int lineStartIdx = UIXML.Text.LastIndexOf('\n', offset);
|
||||||
|
int lineEndIdx = UIXML.Text.IndexOf('\n', offset);
|
||||||
|
|
||||||
string line;
|
string line;
|
||||||
int pos;
|
int pos;
|
||||||
if (lineStartIdx == -1 && lineEndIdx == -1)
|
if (lineStartIdx == -1 && lineEndIdx == -1)
|
||||||
{
|
{
|
||||||
line = UIXML.Text;
|
line = UIXML.Text;
|
||||||
pos = UIXML.CaretOffset;
|
pos = offset;
|
||||||
}
|
}
|
||||||
else if (lineStartIdx == -1)
|
else if (lineStartIdx == -1)
|
||||||
{
|
{
|
||||||
line = UIXML.Text[..(lineEndIdx - 1)];
|
line = UIXML.Text[..(lineEndIdx - 1)];
|
||||||
pos = UIXML.CaretOffset;
|
pos = offset;
|
||||||
}
|
}
|
||||||
else if (lineEndIdx == -1)
|
else if (lineEndIdx == -1)
|
||||||
{
|
{
|
||||||
line = UIXML.Text[(lineStartIdx + 1)..];
|
line = UIXML.Text[(lineStartIdx + 1)..];
|
||||||
pos = UIXML.CaretOffset - lineStartIdx - 2;
|
pos = offset - lineStartIdx - 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
line = UIXML.Text[(lineStartIdx + 1)..(lineEndIdx - 1)];
|
line = UIXML.Text[(lineStartIdx + 1)..(lineEndIdx - 1)];
|
||||||
pos = UIXML.CaretOffset - lineStartIdx - 2;
|
pos = offset - lineStartIdx - 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (line, pos);
|
return (line, pos);
|
||||||
|
Loading…
Reference in New Issue
Block a user