diff --git a/dist/neoeedit.jar b/dist/neoeedit.jar index 114e65e..41a3bc8 100644 Binary files a/dist/neoeedit.jar and b/dist/neoeedit.jar differ diff --git a/src/neoe/ne/Console.java b/src/neoe/ne/Console.java index 0ca56ed..d2171e1 100644 --- a/src/neoe/ne/Console.java +++ b/src/neoe/ne/Console.java @@ -17,9 +17,8 @@ public class Console { private EditorPanel parentUI ; private File dir ; - public Console ( String cmd , OutputStream out , InputStream stdout , - InputStream stderr , Process proc , EditorPanel uiComp , - File dir ) { + public Console ( String cmd , OutputStream out , InputStream stdout , InputStream stderr , Process proc , + EditorPanel uiComp , File dir , boolean follow ) { this . cmd = cmd ; this . out = out ; this . stdout = stdout ; @@ -27,6 +26,7 @@ public Console ( String cmd , OutputStream out , InputStream stdout , this . proc = proc ; this . parentUI = uiComp ; this . dir = dir ; + this . follow = follow ; } public void start ( ) throws Exception { @@ -53,11 +53,10 @@ public void start ( ) throws Exception { new Thread ( ( ) -> { try { proc . waitFor ( ) ; - pp . pageData . editRec . appendLines ( Arrays . asList ( - String . format ( "\nExit(%s) in about %,d ms for\n%s" , proc . exitValue ( ) , - System . currentTimeMillis ( ) - t1 , id ) . split ( "\n" ) ) ) ; + pp . pageData . editRec . appendLines ( Arrays . asList ( String . format ( "\nExit(%s) in about %,d ms for\n%s" , + proc . exitValue ( ) , System . currentTimeMillis ( ) - t1 , id ) . split ( "\n" ) ) ) ; pp . pageData . editRec . appendLine ( "" ) ; - pp . cursor . setSafePos ( 0 , Integer . MAX_VALUE ) ; //go last line + pp . cursor . setSafePos ( 0 , Integer . MAX_VALUE ) ; // go last line finished = true ; pp . adjustCursor ( ) ; pp . uiComp . repaint ( ) ; diff --git a/src/neoe/ne/PlainPage.java b/src/neoe/ne/PlainPage.java index f0aba7d..81afe9c 100644 --- a/src/neoe/ne/PlainPage.java +++ b/src/neoe/ne/PlainPage.java @@ -72,13 +72,14 @@ private static boolean isButtonDown ( int i , MouseEvent evt ) { int selectstartx , selectstarty , selectstopx , selectstopy ; - int showLineCnt ; + int showLineCnt , showLineCnt2 ; int sx , sy ; int toolbarHeight = 25 ; public Paint ui = new Paint ( ) ; public EditorPanel uiComp ; + boolean follow ; private PlainPage ( ) { } @@ -98,6 +99,7 @@ public PlainPage ( EditorPanel editor , PageData data , PlainPage parent ) throw fontList = Conf . defaultFontList ; workPath = parent . workPath ; showLineCnt = parent . showLineCnt ; + follow = parent . follow ; if ( parent . env != null ) env = new LinkedHashMap < > ( parent . env ) ; } else @@ -221,11 +223,11 @@ public void doMoveViewUp ( ) { } public void doMoveViewPageDown ( ) { - sy = Math . min ( sy + showLineCnt , pageData . roLines . getLinesize ( ) - 1 ) ; + sy = Math . min ( sy + showLineCnt2 , pageData . roLines . getLinesize ( ) - 1 ) ; } public void doMoveViewPageUp ( ) { - sy = Math . max ( 0 , sy - showLineCnt ) ; + sy = Math . max ( 0 , sy - showLineCnt2 ) ; } /* let cursor get see */ @@ -235,10 +237,13 @@ public void focusCursor ( ) { /** change cursor to middle of page */ public void adjustCursor ( ) { - if ( showLineCnt == 0 ) { // not yet painted, \ - showLineCnt = Math - . round ( ( uiComp . getSize ( ) . height - toolbarHeight ) / ( ( ui . lineHeight + ui . lineGap ) * ui . scalev ) ) ; // not - // work? + if ( showLineCnt == 0 ) { // not yet painted, + showLineCnt = ( int ) Math + . ceil ( ( uiComp . getSize ( ) . height - toolbarHeight ) / ( ( ui . lineHeight + ui . lineGap ) * ui . scalev ) ) ; + showLineCnt2 = ( int ) Math + . floor ( ( uiComp . getSize ( ) . height - toolbarHeight ) / ( ( ui . lineHeight + ui . lineGap ) * ui . scalev ) ) ; + if ( showLineCnt2 <= 0 ) + showLineCnt2 = 1 ; } int sc = Math . max ( 5 , showLineCnt ) ; sy = Math . max ( 0 , cy - sc / 2 + 1 ) ; @@ -553,6 +558,7 @@ void processCommand ( Commands cmd ) throws Exception { case toggleFollowExec : if ( console != null ) { console . follow = ! console . follow ; + follow = console . follow ; ui . message ( "follow the console:" + console . follow ) ; } break ; @@ -1953,7 +1959,10 @@ public void run ( ) { } // g2.setFont(font); - showLineCnt = Math . round ( ( size . height - toolbarHeight ) / ( ( lineHeight + lineGap ) * scalev ) ) ; + showLineCnt = ( int ) Math . ceil ( ( size . height - toolbarHeight ) / ( ( lineHeight + lineGap ) * scalev ) ) ; + showLineCnt2 = ( int ) Math . floor ( ( size . height - toolbarHeight ) / ( ( lineHeight + lineGap ) * scalev ) ) ; + if ( showLineCnt2 <= 0 ) + showLineCnt2 = 1 ; final int maxw = dim . width - gutterWidth ; final int maxw2 = ( int ) ( maxw / scalev ) ; { // change cy if needed @@ -1978,8 +1987,9 @@ public void run ( ) { drawGutter ( g2 ) ; g2 . scale ( scalev , scalev ) ; // draw text - g2 . translate ( gutterWidth / scalev , 0 ) ; - g2 . setClip ( 0 , 0 , maxw2 , ( int ) ( dim . height / scalev ) ) ; + int gws = ( int ) ( gutterWidth / scalev ) ; + g2 . translate ( gws , 0 ) ; + g2 . setClip ( - gws , 0 , maxw2 + gws , ( int ) ( dim . height / scalev ) ) ; Graphics2D g0 = ( Graphics2D ) g2 . create ( ) ; g0 . setClip ( 0 , 0 , 0 , 0 ) ; // quick hack to not do real draw @@ -2001,8 +2011,7 @@ public void run ( ) { cy = sy + my / ( lineHeight + lineGap ) ; if ( cy >= pageData . roLines . getLinesize ( ) ) { // add a empty line for sake - if ( ! readonly && pageData . roLines . getline ( pageData . roLines . getLinesize ( ) - 1 ) - . length ( ) > 0 ) { + if ( ! readonly && pageData . roLines . getline ( pageData . roLines . getLinesize ( ) - 1 ) . length ( ) > 0 ) { pageData . editRec . insertEmptyLine ( cy ) ; } cy = pageData . roLines . getLinesize ( ) - 1 ; diff --git a/src/neoe/ne/U.java b/src/neoe/ne/U.java index ca32985..3d257c5 100644 --- a/src/neoe/ne/U.java +++ b/src/neoe/ne/U.java @@ -803,8 +803,7 @@ public static void exec ( PlainPage pp , String cmd ) throws Exception { PageData . fromTitle ( String . format ( "[cmd][%s] %s #%s" , dir . getAbsolutePath ( ) , cmd , U . randomID ( ) ) ) , pp ) ; pp2 . workPath = dir . getAbsolutePath ( ) ; pp2 . ptSelection . selectAll ( ) ; - - new Console ( cmd , out , stdout , stderr , proc , pp . uiComp , dir ) . start ( ) ; + new Console ( cmd , out , stdout , stderr , proc , pp . uiComp , dir , pp . follow ) . start ( ) ; } private static void addCmdHistory ( String cmd , String path ) throws IOException { @@ -1106,7 +1105,7 @@ private static String guessByBOM ( byte [ ] src ) { static void guessComment ( PlainPage page ) { List < String > comment = new ArrayList < String > ( ) ; - String [ ] commentchars = { "/*" , "