zoukankan      html  css  js  c++  java
  • Scintilla添加批量注释功能

    下载scite编译 发现支持批量块注释功能,查看scite源码,SciTEBase.cxx文件的StartBlockComment() 函数

    引用了SString 类,而SString 的成员函数在 PropSetFile.cxx 函数中定义

    将PropSetFile.cxx 重命名为SString.cpp,去掉与SString 无关的定义,包含文件保留

    #include "StdAfx.h"
    #include "SString.h"
    #include <sstream>

    将 wEditor.Call 修改为SendMessage

    去掉StartBlockComment()函数 前面的读取配置文件的定义

    代码如下

    bool CScintillaWnd::EndBlockComment() {
     bool placeCommentsAtLineStart = false;

     SString comment = "#"; //#号注释
     SString long_comment = comment;
     long_comment.append(" ");
     int selectionStart = SendMessage(SCI_GETSELECTIONSTART);
     int selectionEnd = SendMessage(SCI_GETSELECTIONEND);
     int caretPosition = SendMessage(SCI_GETCURRENTPOS);
     // checking if caret is located in _beginning_ of selected block
     bool move_caret = caretPosition < selectionEnd;
     int selStartLine = SendMessage(SCI_LINEFROMPOSITION, selectionStart);
     int selEndLine = SendMessage(SCI_LINEFROMPOSITION, selectionEnd);
     int lines = selEndLine - selStartLine;
     int firstSelLineStart = SendMessage(SCI_POSITIONFROMLINE, selStartLine);
     // "caret return" is part of the last selected line
     if ((lines > 0) &&
             (selectionEnd == SendMessage(SCI_POSITIONFROMLINE, selEndLine)))
      selEndLine--;
     SendMessage(SCI_BEGINUNDOACTION);
     for (int i = selStartLine; i <= selEndLine; i++) {
      int lineStart = SendMessage(SCI_POSITIONFROMLINE, i);
      int lineIndent = lineStart;
      int lineEnd = SendMessage(SCI_GETLINEENDPOSITION, i);
      if (!placeCommentsAtLineStart) {
       lineIndent = GetLineIndentPosition(i);
      }
      SString linebuf = GetRange(lineIndent, lineEnd);
      // empty lines are not commented
      if (linebuf.length() < 1)
       continue;
      if (linebuf.startswith(comment.c_str())) {
       int commentLength = static_cast<int>(comment.length());
       if (linebuf.startswith(long_comment.c_str())) {
        // Removing comment with space after it.
        commentLength = static_cast<int>(long_comment.length());
       }
       SendMessage(SCI_SETSEL, lineIndent, lineIndent + commentLength);
       SendMessage(SCI_REPLACESEL, 0, reinterpret_cast<LPARAM>(""));
       if (i == selStartLine) // is this the first selected line?
        selectionStart -= commentLength;
       selectionEnd -= commentLength; // every iteration
       continue;
      }
     }
     // after uncommenting selection may promote itself to the lines
     // before the first initially selected line;
     // another problem - if only comment symbol was selected;
     if (selectionStart < firstSelLineStart) {
      if (selectionStart >= selectionEnd - (static_cast<int>(long_comment.length()) - 1))
       selectionEnd = firstSelLineStart;
      selectionStart = firstSelLineStart;
     }
     if (move_caret) {
      // moving caret to the beginning of selected block
      SendMessage(SCI_GOTOPOS, selectionEnd);
      SendMessage(SCI_SETCURRENTPOS, selectionStart);
     } else {
      SendMessage(SCI_SETSEL, selectionStart, selectionEnd);
     }
     SendMessage(SCI_ENDUNDOACTION);
     return true;
    }

    在头文件中包含 #include "SString.h"

     后将代码修改为两个快捷键,一个 加注释 一个去注释

  • 相关阅读:
    ES6 数值
    ES6 字符串
    ES6 Reflect 与 Proxy
    ES6 Map 与 Set
    es6 Symbol
    新兴的API(fileReader、geolocation、web计时、web worker)
    浏览器数据库 IndexedDB 入门教程
    离线应用与客户端存储(cookie storage indexedDB)
    javascript高级技巧篇(作用域安全、防篡改、惰性载入、节流、自定义事件,拖放)
    ajax与comet
  • 原文地址:https://www.cnblogs.com/sitemaker/p/2626967.html
Copyright © 2011-2022 走看看