{
EditView View;
Document _Document;
- bool keepAnchor = false;
public Controller(Document doc, EditView view)
{
this.View = view;
this.View.render.ChangedRenderResource += render_ChangedRenderResource;
this.View.PageBoundChanged += View_PageBoundChanged;
- this.Document.Clear();
+ //this.Document.Clear();
}
public Document Document
private void _Document_CaretChanged(object sender, EventArgs e)
{
- if (keepAnchor)
- return;
TextPoint pos = this.Document.CaretPostion;
this.JumpCaret(pos.row, pos.col);
}
{
if (this.IsReverseSelect())
{
- this.Document.SelectGrippers.BottomRight.MoveByIndex(this.View, this.SelectionStart);
- this.Document.SelectGrippers.BottomLeft.MoveByIndex(this.View, this.SelectionStart + this.SelectionLength);
+ if (this.Document.SelectGrippers.BottomRight.Enabled)
+ this.Document.SelectGrippers.BottomRight.MoveByIndex(this.View, this.SelectionStart);
+ if (this.Document.SelectGrippers.BottomLeft.Enabled)
+ this.Document.SelectGrippers.BottomLeft.MoveByIndex(this.View, this.SelectionStart + this.SelectionLength);
}
else
{
- this.Document.SelectGrippers.BottomLeft.MoveByIndex(this.View, this.SelectionStart);
- this.Document.SelectGrippers.BottomRight.MoveByIndex(this.View, this.SelectionStart + this.SelectionLength);
+ if (this.Document.SelectGrippers.BottomLeft.Enabled)
+ this.Document.SelectGrippers.BottomLeft.MoveByIndex(this.View, this.SelectionStart);
+ if (this.Document.SelectGrippers.BottomRight.Enabled)
+ this.Document.SelectGrippers.BottomRight.MoveByIndex(this.View, this.SelectionStart + this.SelectionLength);
}
}
/// <param name="alignWord">単語単位で移動するなら真。そうでないなら偽</param>
public void MoveCaretHorizontical(int realLength, bool isSelected,bool alignWord = false)
{
- keepAnchor = true;
for (int i = Math.Abs(realLength); i > 0; i--)
{
bool MoveFlow = realLength > 0;
}
this.View.AdjustCaretAndSrc(AdjustFlow.Col);
this.SelectWithMoveCaret(isSelected);
- keepAnchor = false;
}
void AlignNearestWord(bool MoveFlow)
/// <param name="isSelected"></param>
public void MoveCaretVertical(int deltarow,bool isSelected)
{
- keepAnchor = true;
for (int i = Math.Abs(deltarow); i > 0; i--)
this.MoveCaretVertical(deltarow > 0);
this.View.AdjustCaretAndSrc(AdjustFlow.Both);
this.SelectWithMoveCaret(isSelected);
- keepAnchor = false;
}
/// <summary>
if (this.Document[index] == Document.NewLine)
next = index + 1;
- this.Document.Replace(index, next - index, "");
+ this.Document.Replace(index, next - index, "", true);
}
public bool IsRectInsertMode()
newIndex--;
}
- this.Document.Replace(newIndex, oldIndex - newIndex, "");
+ this.Document.Replace(newIndex, oldIndex - newIndex, "", true);
}
/// <summary>
if (foldingData != null && !foldingData.Expand && index > foldingData.Start && index <= foldingData.End)
index = foldingData.End + 1;
}
- this.Document.Replace(index, length, str);
+ this.Document.Replace(index, length, str, true);
}
/// <summary>
/// JumpCaretで移動した位置からキャレットを移動し、選択状態にする
/// </summary>
/// <param name="tp"></param>
- public void MoveCaretAndSelect(TextPoint tp)
+ /// <param name="alignWord">単語単位で選択するかどうか</param>
+ public void MoveCaretAndSelect(TextPoint tp,bool alignWord = false)
{
- keepAnchor = true;
+ TextPoint endSelectPostion = tp;
int CaretPostion = this.View.GetIndexFromLayoutLine(tp);
+ if (alignWord)
+ {
+ if (this.IsReverseSelect())
+ while (CaretPostion >= 0 && CaretPostion < this.Document.Length && !Util.IsWordSeparator(this.Document[CaretPostion])) CaretPostion--;
+ else
+ while (CaretPostion < this.Document.Length && !Util.IsWordSeparator(this.Document[CaretPostion])) CaretPostion++;
+ if (CaretPostion < 0)
+ CaretPostion = 0;
+ endSelectPostion = this.View.LayoutLines.GetTextPointFromIndex(CaretPostion);
+ }
this.Document.Select(this.Document.AnchorIndex, CaretPostion - this.Document.AnchorIndex);
- this.View.JumpCaret(tp.row, tp.col);
+ this.View.JumpCaret(endSelectPostion.row, endSelectPostion.col);
this.View.AdjustCaretAndSrc();
- keepAnchor = false;
}
/// <summary>
return;
int selectionStart = this.SelectionStart;
string insertStr = this.IndentMode == IndentMode.Space ? this.GetIndentSpace(0) : "\t";
- string text = this.RemoveLineHead(GetTextFromLineSelectArea(this.View.Selections), insertStr);
+ string text = this.RemoveLineHead(GetTextFromLineSelectArea(this.View.Selections), insertStr, insertStr.Length);
this.RepleaceSelectionArea(this.View.Selections, text);
this.Document.Select(selectionStart, text.Length);
}
return output.ToString();
}
- public string RemoveLineHead(string s, string str)
+ public string RemoveLineHead(string s, string str,int remove_count)
{
string[] lines = s.Split(new string[] { Document.NewLine.ToString() }, StringSplitOptions.None);
StringBuilder output = new StringBuilder();
for (int i = 0; i < lines.Length; i++)
{
if (lines[i].StartsWith(str))
- output.Append(lines[i].Substring(1) + Document.NewLine);
+ output.Append(lines[i].Substring(remove_count) + Document.NewLine);
else if (i < lines.Length - 1)
output.Append(lines[i] + Document.NewLine);
}