/// </summary>
public enum IndentMode
{
+ /// <summary>
+ /// タブ
+ /// </summary>
Tab,
+ /// <summary>
+ /// スペース
+ /// </summary>
Space,
}
this.Document = doc;
this.View = view;
this.View.render.ChangedRenderResource += render_ChangedRenderResource;
- this.View.PerformLayouted += View_LineBreakChanged;
this.View.PageBoundChanged += View_PageBoundChanged;
- this.Document.Clear();
+ //this.Document.Clear();
}
public Document Document
this._Document.Update -= Document_Update;
this._Document.StatusUpdate -= Document_StatusChanged;
this._Document.SelectionChanged -= Document_SelectionChanged;
+ this._Document.PerformLayouted -= View_LineBreakChanged;
+ this._Document.CaretChanged -= _Document_CaretChanged;
}
this._Document = value;
this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
this._Document.StatusUpdate += Document_StatusChanged;
this._Document.SelectionChanged += Document_SelectionChanged;
+ this._Document.PerformLayouted += View_LineBreakChanged;
+ this._Document.CaretChanged += _Document_CaretChanged;
}
}
+ private void _Document_CaretChanged(object sender, EventArgs e)
+ {
+ TextPoint pos = this.Document.CaretPostion;
+ this.JumpCaret(pos.row, pos.col);
+ }
+
private void Document_SelectionChanged(object sender, EventArgs e)
{
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);
}
}
else
return false;
}
- this.Document.Lock();
this.Document.Replace(this.SelectionStart, this.SelectionLength, result.ToString());
- this.Document.UnLock();
return true;
}
else
i++;
}
- this.Document.Lock();
this.Document.Replace(this.SelectionStart, this.SelectionLength, result.ToString());
- this.Document.UnLock();
}
/// <summary>
{
foreach(int id in this.Document.Markers.IDs)
{
- foreach (Marker m in this.Document.GetMarkers(index, id))
+ foreach (Marker m in this.Document.GetMarkers(id, index))
{
if (m.hilight == type)
return true;
if (this.Document[index] == Document.NewLine)
next = index + 1;
- this.Document.Lock();
- this.Document.Replace(index, next - index, "");
- this.Document.UnLock();
+ this.Document.Replace(index, next - index, "", true);
}
public bool IsRectInsertMode()
newIndex--;
}
- this.Document.Lock();
- this.Document.Replace(newIndex, oldIndex - newIndex, "");
- this.Document.UnLock();
+ 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.Lock();
- this.Document.Replace(index, length, str);
- this.Document.UnLock();
+ 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)
{
+ 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();
}
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);
}
throw new InvalidOperationException("");
TextPoint nextPoint = this.GetTextPointAfterMoveLine(isMoveNext ? 1 : -1, this.Document.CaretPostion);
-
+
this.View.JumpCaret(nextPoint.row, nextPoint.col,false);
}
private void ReplaceBeforeSelection(Selection sel, int removeLength, string insertStr)
{
sel = Util.NormalizeIMaker<Selection>(sel);
- this.Document.Lock();
this.Document.Replace(sel.start - removeLength, removeLength, insertStr);
- this.Document.UnLock();
}
private void RepleaceSelectionArea(SelectCollection Selections, string value,bool updateInsertPoint = false)
if (Selections.Count > 0)
sel = Util.NormalizeIMaker<Selection>(this.View.Selections.First());
- this.Document.Lock();
this.Document.Replace(sel.start, sel.length, value);
- this.Document.UnLock();
return;
}
{
int i;
- this.Document.Lock();
-
this.Document.UndoManager.BeginUndoGroup();
this.Document.FireUpdateEvent = false;
this.Document.FireUpdateEvent = true;
this.Document.UndoManager.EndUndoGroup();
-
- this.Document.UnLock();
}
else
{
SelectCollection temp = new SelectCollection(this.View.Selections); //コピーしないとReplaceCommandを呼び出した段階で書き換えられてしまう
- this.Document.Lock();
-
this.Document.UndoManager.BeginUndoGroup();
this.Document.FireUpdateEvent = false;
this.Document.FireUpdateEvent = true;
this.Document.UndoManager.EndUndoGroup();
-
- this.Document.UnLock();
}
this.JumpCaret(StartIndex);
if (updateInsertPoint && newInsertPoint.Count > 0)
void View_PageBoundChanged(object sender, EventArgs e)
{
if (this.Document.LineBreak == LineBreakMethod.PageBound && this.View.PageBound.Width - this.View.LineBreakingMarginWidth > 0)
- this.View.PerfomLayouts();
+ this.Document.PerformLayout();
this.AdjustCaret();
}
if (e.type == ResourceType.Font)
{
if (this.Document.LineBreak == LineBreakMethod.PageBound)
- this.View.PerfomLayouts();
+ this.Document.PerformLayout();
this.AdjustCaret();
}
if (e.type == ResourceType.InlineChar)