Fix scrolling in MessageBox, file overwrite confirmation
This commit is contained in:
		@@ -402,6 +402,16 @@ class Editor
 | 
				
			|||||||
        if (!$saveTo) {
 | 
					        if (!$saveTo) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        if (file_exists($saveTo)) {
 | 
				
			||||||
 | 
					            $overwrite = (new Menu($this->term, [
 | 
				
			||||||
 | 
					                'overwrite' => "Overwrite the file",
 | 
				
			||||||
 | 
					                'abort' => "Abort"
 | 
				
			||||||
 | 
					            ], "The file exists"))->display(0, 0, 30, 0, '');
 | 
				
			||||||
 | 
					            if ($overwrite == 'abort') {
 | 
				
			||||||
 | 
					                $this->redrawEditor();
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $doc = $this->document->save();
 | 
					        $doc = $this->document->save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -958,7 +968,7 @@ Welcome to JSONEdit! The editor you never knew you were missing!
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# QuickStart
 | 
					# QuickStart
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To get started, press I (shift-i) and add something to the document. Use the arrow keys to get around. To cancel a prompt, close a menu or close a dialog, press ctrl-C. When you are happy with your work, press ctrl-W and enter a filename to write. You can also press ctrl-R and read in a new file, overwriting your masterpiece.
 | 
					To get started, press I (shift-i) and add something to the document. Use the arrow keys to get around. To cancel a prompt, close a menu or close a dialog, press ctrl-C. When you are happy with your work, press ctrl-W and enter a filename to write. You can also press ctrl-O to browse for a file to open.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Useful keys
 | 
					# Useful keys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@ class MessageBox
 | 
				
			|||||||
    const U_EDGE_HORIZONTAL = "\u{2500}";
 | 
					    const U_EDGE_HORIZONTAL = "\u{2500}";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const U_EDGE_VERTICAL = "\u{2502}";
 | 
					    const U_EDGE_VERTICAL = "\u{2502}";
 | 
				
			||||||
    const U_EDGE_VERTICAL_SCROLL = "\u{2591}";
 | 
					    const U_EDGE_VERTICAL_SCROLL = "\u{2593}";
 | 
				
			||||||
    const U_EDGE_VERTICAL_THUMB = "\u{2593}";
 | 
					    const U_EDGE_VERTICAL_THUMB = "\u{2593}";
 | 
				
			||||||
    const U_EDGE_VERTICAL_LEFT = "\u{2524}";
 | 
					    const U_EDGE_VERTICAL_LEFT = "\u{2524}";
 | 
				
			||||||
    const U_EDGE_VERTICAL_RIGHT = "\u{251c}";
 | 
					    const U_EDGE_VERTICAL_RIGHT = "\u{251c}";
 | 
				
			||||||
@@ -76,14 +76,36 @@ class MessageBox
 | 
				
			|||||||
                    $showing = false;
 | 
					                    $showing = false;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                if ($ch == "k{UP}") {
 | 
					                switch ($ch) {
 | 
				
			||||||
                    $this->scroll--;
 | 
					                    case "k{UP}":
 | 
				
			||||||
                    if ($this->scroll < 0) $this->scroll = 0;
 | 
					                        $this->scroll--;
 | 
				
			||||||
                    $this->redraw($left, $top, $width, $height, $wrapped, $this->title, $maxScroll);
 | 
					                        if ($this->scroll < 0) $this->scroll = 0;
 | 
				
			||||||
                } elseif ($ch == "k{DOWN}") {
 | 
					                        $this->redraw($left, $top, $width, $height, $wrapped, $this->title, $maxScroll);
 | 
				
			||||||
                    $this->scroll++;
 | 
					                        break;
 | 
				
			||||||
                    if ($this->scroll > $maxScroll) $this->scroll = $maxScroll; 
 | 
					                    case "k{DOWN}":
 | 
				
			||||||
                    $this->redraw($left, $top, $width, $height, $wrapped, $this->title, $maxScroll);
 | 
					                        $this->scroll++;
 | 
				
			||||||
 | 
					                        if ($this->scroll > $maxScroll) $this->scroll = $maxScroll; 
 | 
				
			||||||
 | 
					                        $this->redraw($left, $top, $width, $height, $wrapped, $this->title, $maxScroll);
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
 | 
					                    case "k{PGUP}":
 | 
				
			||||||
 | 
					                        $this->scroll -= $height - 2;
 | 
				
			||||||
 | 
					                        if ($this->scroll < 0) $this->scroll = 0;
 | 
				
			||||||
 | 
					                        $this->redraw($left, $top, $width, $height, $wrapped, $this->title, $maxScroll);
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
 | 
					                    case "k{PGDN}":
 | 
				
			||||||
 | 
					                        $this->scroll += $height - 2;
 | 
				
			||||||
 | 
					                        if ($this->scroll >= $maxScroll) $this->scroll = $maxScroll;
 | 
				
			||||||
 | 
					                        $this->redraw($left, $top, $width, $height, $wrapped, $this->title, $maxScroll);
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
 | 
					                    case "k{HOME}":
 | 
				
			||||||
 | 
					                        $this->scroll = 0;
 | 
				
			||||||
 | 
					                        if ($this->scroll >= count($wrapped)) $this->scroll = 0;
 | 
				
			||||||
 | 
					                        $this->redraw($left, $top, $width, $height, $wrapped, $this->title, $maxScroll);
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
 | 
					                    case "k{END}":
 | 
				
			||||||
 | 
					                        $this->scroll = $maxScroll;
 | 
				
			||||||
 | 
					                        $this->redraw($left, $top, $width, $height, $wrapped, $this->title, $maxScroll);
 | 
				
			||||||
 | 
					                        break;    
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -154,7 +176,7 @@ class MessageBox
 | 
				
			|||||||
            if ($n >= $thumbTop && $n <= $thumbBottom) {
 | 
					            if ($n >= $thumbTop && $n <= $thumbBottom) {
 | 
				
			||||||
                $scrollbar = "\e[97;1m".self::U_EDGE_VERTICAL_THUMB."\e[40;37;22m";
 | 
					                $scrollbar = "\e[97;1m".self::U_EDGE_VERTICAL_THUMB."\e[40;37;22m";
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                $scrollbar = "\e[37;2m".self::U_EDGE_VERTICAL_SCROLL."\e[40;37;22m";
 | 
					                $scrollbar = "\e[30;2m".self::U_EDGE_VERTICAL_SCROLL."\e[40;37;22m";
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            $this->terminal
 | 
					            $this->terminal
 | 
				
			||||||
                ->writeAt($left, $top + 3 + $n, self::U_EDGE_VERTICAL.$item.$scrollbar);
 | 
					                ->writeAt($left, $top + 3 + $n, self::U_EDGE_VERTICAL.$item.$scrollbar);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user