Пример #1
0
        private void FormatOnEnter(SnapshotPoint start, SnapshotPoint end) {
            if (NodejsPackage.Instance.FormattingGeneralOptionsPage.FormatOnEnter) {
                var insertionPoint = _textView.BufferGraph.MapDownToInsertionPoint(
                    _textView.Caret.Position.BufferPosition,
                    PointTrackingMode.Negative,
                    x => x.ContentType.IsOfType(NodejsConstants.Nodejs)
                );

                if (insertionPoint != null) {
                    var buffer = insertionPoint.Value.Snapshot.TextBuffer;
                    var line = insertionPoint.Value.GetContainingLine();

                    if (line.LineNumber > 0) {
                        SnapshotSpan commentSpan;
                        if (insertionPoint.Value.IsMultilineComment(out commentSpan)) {
                            _textView.FormatMultilineComment(commentSpan.Start, insertionPoint.Value);
                        } else {
                            ApplyEdits(
                                buffer,
                                Formatter.GetEditsAfterEnter(
                                    buffer.CurrentSnapshot.GetText(),
                                    start.TranslateTo(buffer.CurrentSnapshot, PointTrackingMode.Negative),
                                    end.TranslateTo(buffer.CurrentSnapshot, PointTrackingMode.Positive),
                                    CreateFormattingOptions()
                                )
                            );
                        }
                    }
                }
            }
        }