fix an integer division by zero of text_editor issue
This commit is contained in:
		
							parent
							
								
									32d988e1a7
								
							
						
					
					
						commit
						108a31d907
					
				@ -477,7 +477,8 @@ namespace nana{	namespace widgets
 | 
				
			|||||||
			std::size_t	_m_textline_from_screen(int y) const
 | 
								std::size_t	_m_textline_from_screen(int y) const
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				const std::size_t textlines = editor_.textbase_.lines();
 | 
									const std::size_t textlines = editor_.textbase_.lines();
 | 
				
			||||||
				if (0 == textlines)
 | 
									const auto line_px = static_cast<int>(editor_.line_height());
 | 
				
			||||||
 | 
									if ((0 == textlines) || (0 == line_px))
 | 
				
			||||||
					return 0;
 | 
										return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				const int offset_top = editor_.points_.offset.y;
 | 
									const int offset_top = editor_.points_.offset.y;
 | 
				
			||||||
@ -486,7 +487,7 @@ namespace nana{	namespace widgets
 | 
				
			|||||||
				if (y < text_area_top)
 | 
									if (y < text_area_top)
 | 
				
			||||||
					y = offset_top ? offset_top - 1 : 0;
 | 
										y = offset_top ? offset_top - 1 : 0;
 | 
				
			||||||
				else
 | 
									else
 | 
				
			||||||
					y = (y - text_area_top) / static_cast<int>(editor_.line_height()) + offset_top;
 | 
										y = (y - text_area_top) / line_px + offset_top;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				return (textlines <= static_cast<std::size_t>(y) ? textlines - 1 : static_cast<std::size_t>(y));
 | 
									return (textlines <= static_cast<std::size_t>(y) ? textlines - 1 : static_cast<std::size_t>(y));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@ -1106,28 +1107,24 @@ namespace nana{	namespace widgets
 | 
				
			|||||||
			//secondary, index of line that the text was splitted into multilines.
 | 
								//secondary, index of line that the text was splitted into multilines.
 | 
				
			||||||
			std::size_t _m_textline_from_screen(int y, std::size_t & secondary) const
 | 
								std::size_t _m_textline_from_screen(int y, std::size_t & secondary) const
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				const int text_area_top = editor_.text_area_.area.y;
 | 
									const auto line_px = static_cast<int>(editor_.line_height());
 | 
				
			||||||
				const int offset_top = editor_.points_.offset.y;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if (0 == editor_.textbase_.lines())
 | 
									if ((0 == editor_.textbase_.lines()) || (0 == line_px))
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					secondary = 0;
 | 
										secondary = 0;
 | 
				
			||||||
					return 0;
 | 
										return 0;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				std::size_t screen_line;
 | 
									const int text_area_top = editor_.text_area_.area.y;
 | 
				
			||||||
				if (y < text_area_top)
 | 
									const int offset_top = editor_.points_.offset.y;
 | 
				
			||||||
				{
 | 
					
 | 
				
			||||||
					screen_line = (text_area_top - y) / static_cast<int>(editor_.line_height());
 | 
									auto screen_line = (text_area_top - y) / line_px;
 | 
				
			||||||
					if (screen_line > static_cast<std::size_t>(offset_top))
 | 
									if ((y < text_area_top) && (screen_line > offset_top))
 | 
				
			||||||
					screen_line = 0;
 | 
										screen_line = 0;
 | 
				
			||||||
				else
 | 
									else
 | 
				
			||||||
						screen_line = static_cast<std::size_t>(offset_top)-screen_line;
 | 
										screen_line = offset_top - screen_line;
 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				else
 | 
					 | 
				
			||||||
					screen_line = static_cast<std::size_t>((y - text_area_top) / static_cast<int>(editor_.line_height()) + offset_top);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
				auto primary = _m_textline(screen_line, secondary);
 | 
									auto primary = _m_textline(static_cast<std::size_t>(screen_line), secondary);
 | 
				
			||||||
				if (primary < linemtr_.size())
 | 
									if (primary < linemtr_.size())
 | 
				
			||||||
					return primary;
 | 
										return primary;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user