Fix level popping
This commit is contained in:
		
							parent
							
								
									36454fb90c
								
							
						
					
					
						commit
						081b4db5c3
					
				
							
								
								
									
										39
									
								
								sdn.cpp
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								sdn.cpp
									
									
									
									
									
								
							| @ -866,6 +866,24 @@ fun search (const wstring &needle) { | |||||||
| 	g.cursor = best; | 	g.cursor = best; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | fun fix_cursor_and_offset () { | ||||||
|  | 	g.cursor = max (g.cursor, 0); | ||||||
|  | 	g.cursor = min (g.cursor, int (g.entries.size ()) - 1); | ||||||
|  | 
 | ||||||
|  | 	// Decrease the offset when more items can suddenly fit
 | ||||||
|  | 	int pushable = visible_lines () - (int (g.entries.size ()) - g.offset); | ||||||
|  | 	g.offset -= max (pushable, 0); | ||||||
|  | 
 | ||||||
|  | 	// Make sure cursor is visible
 | ||||||
|  | 	g.offset = max (g.offset, 0); | ||||||
|  | 	g.offset = min (g.offset, int (g.entries.size ()) - 1); | ||||||
|  | 
 | ||||||
|  | 	if (g.offset > g.cursor) | ||||||
|  | 		g.offset = g.cursor; | ||||||
|  | 	if (g.cursor - g.offset >= visible_lines ()) | ||||||
|  | 		g.offset = g.cursor - visible_lines () + 1; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| fun is_ancestor_dir (const string &ancestor, const string &of) -> bool { | fun is_ancestor_dir (const string &ancestor, const string &of) -> bool { | ||||||
| 	if (strncmp (ancestor.c_str (), of.c_str (), ancestor.length ())) | 	if (strncmp (ancestor.c_str (), of.c_str (), ancestor.length ())) | ||||||
| 		return false; | 		return false; | ||||||
| @ -883,8 +901,8 @@ fun pop_levels () { | |||||||
| 		i++; | 		i++; | ||||||
| 		g.levels.pop_back (); | 		g.levels.pop_back (); | ||||||
| 	} | 	} | ||||||
| 	if (!anchor.empty () && (g.cursor >= g.entries.size () | 	fix_cursor_and_offset (); | ||||||
| 	 || g.entries[g.cursor].filename != anchor)) | 	if (!anchor.empty () && g.entries[g.cursor].filename != anchor) | ||||||
| 		search (to_wide (anchor)); | 		search (to_wide (anchor)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -1064,22 +1082,7 @@ fun handle (wint_t c) -> bool { | |||||||
| 		if (c != KEY (RESIZE) && c != WEOF) | 		if (c != KEY (RESIZE) && c != WEOF) | ||||||
| 			beep (); | 			beep (); | ||||||
| 	} | 	} | ||||||
| 	g.cursor = max (g.cursor, 0); | 	fix_cursor_and_offset (); | ||||||
| 	g.cursor = min (g.cursor, int (g.entries.size ()) - 1); |  | ||||||
| 
 |  | ||||||
| 	// Decrease the offset when more items can suddenly fit
 |  | ||||||
| 	int pushable = visible_lines () - (int (g.entries.size ()) - g.offset); |  | ||||||
| 	g.offset -= max (pushable, 0); |  | ||||||
| 
 |  | ||||||
| 	// Make sure cursor is visible
 |  | ||||||
| 	g.offset = max (g.offset, 0); |  | ||||||
| 	g.offset = min (g.offset, int (g.entries.size ()) - 1); |  | ||||||
| 
 |  | ||||||
| 	if (g.offset > g.cursor) |  | ||||||
| 		g.offset = g.cursor; |  | ||||||
| 	if (g.cursor - g.offset >= visible_lines ()) |  | ||||||
| 		g.offset = g.cursor - visible_lines () + 1; |  | ||||||
| 
 |  | ||||||
| 	update (); | 	update (); | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user