Download
Magazine
Develop
Account
Download
Magazine
Develop
Login
Forgot Account/Password
Create Account
Language
Help
Language
Help
×
Login
Login Name
Password
×
Forgot Account/Password
Category:
Software
People
PersonalForge
Magazine
Wiki
Search
OSDN
>
Find Software
>
Text Editors
>
Azuki
>
Forums
>
公開討議
>
Caretを、指定した行/列インデックスへ移動する方法を教えて下さい。
Azuki
Description
Project Summary
Developer Dashboard
Web Page
Developers
Image Gallery
List of RSS Feeds
Activity
Statistics
History
Downloads
List of Releases
Stats
Source Code
Code Repository list
Subversion
View Repository
Ticket
Ticket List
Milestone List
Type List
Component List
List of frequently used tickets/RSS
Submit New Ticket
Documents
FrontPage
Title index
Recent changes
Communication
List of Forums
公開討議 (499)
Forums:
公開討議
(Thread #44492)
Return to Thread list
RSS
Caretを、指定した行/列インデックスへ移動する方法を教えて下さい。 (2021-08-07 16:31 by
kazmax
#87863)
Reply
①Enterで改行後、改行前の行の先頭に全角空白があれば数を数えて、同じ数の全角空白を新らしい行の先頭に自動挿入する。
②挿入後、Caretを、挿入された全角空白の最後の位置に移動する。
という機能を作っています。
①は出来るのですが、②が出来ません。
どのようにすればよいでしょうか。
実装は下記のとおりです。
private void AzukiEditor_TextChanged(object sender, EventArgs e)
{
if (LastInputedKey == Keys.Enter)
{
int newLineIndex = AzukiEditor.GetLineIndexFromCharIndex(AzukiEditor.CaretIndex);
if (newLineIndex != 0)
{
string prevLine = AzukiEditor.Document.GetLineContent(newLineIndex - 1);
if (prevLine.StartsWith(" "))
{
string headSpaces = "";
for (int i = 0; i < prevLine.Length; i++)
{
if (prevLine[i] == ' ')
{
headSpaces += " ";
}
else
{
break;
}
}
AzukiEditor.TextChanged -= AzukiEditor_TextChanged;
AzukiEditor.Document.Text = AzukiEditor.Document.Text.Insert(AzukiEditor.CaretIndex, headSpaces);
AzukiEditor.TextChanged += AzukiEditor_TextChanged;
headSpaces = "";
}
}
}
}
Reply to #87863
×
Subject
Body
Reply To Message #87863 > ①Enterで改行後、改行前の行の先頭に全角空白があれば数を数えて、同じ数の全角空白を新らしい行の先頭に自動挿入する。 > ②挿入後、Caretを、挿入された全角空白の最後の位置に移動する。 > という機能を作っています。 > > ①は出来るのですが、②が出来ません。 > どのようにすればよいでしょうか。 > > 実装は下記のとおりです。 > > private void AzukiEditor_TextChanged(object sender, EventArgs e) > { > if (LastInputedKey == Keys.Enter) > { > int newLineIndex = AzukiEditor.GetLineIndexFromCharIndex(AzukiEditor.CaretIndex); > if (newLineIndex != 0) > { > string prevLine = AzukiEditor.Document.GetLineContent(newLineIndex - 1); > if (prevLine.StartsWith(" ")) > { > string headSpaces = ""; > for (int i = 0; i < prevLine.Length; i++) > { > if (prevLine[i] == ' ') > { > headSpaces += " "; > } > else > { > break; > } > } > AzukiEditor.TextChanged -= AzukiEditor_TextChanged; > AzukiEditor.Document.Text = AzukiEditor.Document.Text.Insert(AzukiEditor.CaretIndex, headSpaces); > AzukiEditor.TextChanged += AzukiEditor_TextChanged; > headSpaces = ""; > } > } > } > }
You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.)
Login
Nickname
Preview
Post
Cancel
Re: Caretを、指定した行/列インデックスへ移動する方法を教えて下さい。 (2021-08-07 22:45 by
kazmax
#87864)
Reply
自己解決しました。
private void AzukiEditor_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
int prevLineIndex = AzukiEditor.GetLineIndexFromCharIndex(AzukiEditor.Document.CaretIndex);
string prevLineText = AzukiEditor.Document.GetLineContent(prevLineIndex);
string headSpaces = "";
if (prevLineText.StartsWith(" "))
{
for (int i = 0; i < prevLineText.Length; i++)
{
if (prevLineText[i] == ' ')
{
headSpaces += " ";
}
else
{
break;
}
}
e.Handled = true;
AzukiEditor.Document.Replace(Environment.NewLine + headSpaces, AzukiEditor.Document.CaretIndex, AzukiEditor.CaretIndex);
}
}
}
Reply to
#87863
Reply to #87864
×
Subject
Body
Reply To Message #87864 > 自己解決しました。 > > private void AzukiEditor_KeyPress(object sender, KeyPressEventArgs e) > { > if (e.KeyChar == (char)Keys.Enter) > { > int prevLineIndex = AzukiEditor.GetLineIndexFromCharIndex(AzukiEditor.Document.CaretIndex); > string prevLineText = AzukiEditor.Document.GetLineContent(prevLineIndex); > > string headSpaces = ""; > if (prevLineText.StartsWith(" ")) > { > for (int i = 0; i < prevLineText.Length; i++) > { > if (prevLineText[i] == ' ') > { > headSpaces += " "; > } > else > { > break; > } > } > e.Handled = true; > AzukiEditor.Document.Replace(Environment.NewLine + headSpaces, AzukiEditor.Document.CaretIndex, AzukiEditor.CaretIndex); > } > } > }
You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.)
Login
Nickname
Preview
Post
Cancel